Uploaded image for project: 'Spring Data Redis'
  1. Spring Data Redis
  2. DATAREDIS-1001

Jackson2HashMapper does not serialize Date/Calender fields when flatten = true

    Details

      Description

      Jackson2HashMapper does not serialize Date/Calendar fields when flatten set to true.

      For below POJO,

      public class Employee implements Serializable { 
       private String employeeId; 
       private String firstName; 
       private String lastName; 
       private Calendar dateOfJoining; private Date createdDate = new Date(); 
       private Date updatedDate = new Date(); 
      }
      
      public class Employee implements Serializable { 
      
        private String employeeId; 
        private String firstName; 
        private String lastName; 
        private Calendar dateOfJoining; 
        private Date createdDate = new Date(); 
        private Date updatedDate = new Date(); 
      }
      

       

      Configuration used,

      @Configuration public class SpringDataRedisConfiguration {      
      
        @Bean 
        public RedisConnectionFactory redisConnectionFactory() { 
            RedisStandaloneConfiguration redisConfiguration = new          RedisStandaloneConfiguration(host, port); 
            redisConfiguration.setDatabase(database); 
            return new LettuceConnectionFactory(redisConfiguration); 
        }    
      
        @Bean 
        public StringRedisTemplate stringRedisTemplate(RedisConnectionFactory     redisConnectionFactory) { 
            return new StringRedisTemplate(redisConnectionFactory); 
        }    
       
        @Bean 
        public HashMapper<Employee, String, String> jacksonHashMapper() { 
           return new DecoratingStringHashMapper(new Jackson2HashMapper(true)); 
        }
       
      }
      

       

       

      Used as below,

      @Autowired
      private HashOperations<String, String, String> hashOperations;
       
      @Autowired
      private HashMapper<Employee, String, String> hashMapper;
      
      public void save(Employee employee) {
         employee.setEmployeeId(UUID.randomUUID().toString());
         Map<String, String> employeeHash = hashMapper.toHash(employee);
         hashOperations.putAll(employee.getEmployeeId(), employeeHash);
      }
      

       

       

      When I disable fattening, using 

      @Bean
         public HashMapper<Employee, String, String> jacksonHashMapper() {
             return new DecoratingStringHashMapper(new Jackson2HashMapper(false));
         }
      

      It serializes the Date/Calendar fields correctly.

        Attachments

          Activity

            People

            • Assignee:
              cstrobl Christoph Strobl
              Reporter:
              amipatil Amit Ashok Patil
              Last updater:
              Mark Paluch
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: