Skip to content

Jackson2HashMapper does not serialize Date/Calender fields when flatten = true [DATAREDIS-1001] #1572

@spring-projects-issues

Description

@spring-projects-issues

Amit Ashok Patil opened DATAREDIS-1001 and commented

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


Affects: 2.1.9 (Lovelace SR9)

Referenced from: pull request #467

Backported to: 2.1.10 (Lovelace SR10)

Metadata

Metadata

Labels

in: coreIssues in core supporttype: bugA general bug

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions