我很难理解这里发生了什么。我正在使用jackson2hashmapper和decoratingstringhashmapper将哈希转换为自定义对象,并引发以下异常java.lang.classcastexception:class java.util.linkedhashmap不能转换为class domain.data。任何反馈都将不胜感激。谢谢。
@Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory, ObjectMapper objectMapper) {
final RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(connectionFactory);
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer(objectMapper));
return redisTemplate;
}
@Bean
public Jackson2HashMapper jackson2HashMapper(ObjectMapper objectMapper) {
return new Jackson2HashMapper(objectMapper, false);
}
@Resource(name = "redisTemplate")
private HashOperations<String, String, Map<String, String>> hashOperations;
@Autowired
private Jackson2HashMapper jackson2HashMapper;
List<Map<String, String>> hashValues = hashOperations.multiGet("name", keys);
HashMapper<Data, String, Object> hashMapper = new DecoratingStringHashMapper(jackson2HashMapper);
Data data = hashMapper.fromHash(hashValues.get(0));
暂无答案!
目前还没有任何答案,快来回答吧!