-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Labels
Milestone
Description
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)