【发布时间】:2017-10-16 22:26:51
【问题描述】:
我正在我的组织中创建自定义缓存架构,并且必须序列化 ResponseEntity 对象。我正在使用 GenericJackson2JsonRedisSerializer 来序列化对象,但是当它是 ResponseEntity 时它不接受。
我使用 Jackson 序列化器的自定义 redis 模板:
@Bean
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> template = new CustomRedisTemplate<String, Object>();
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
template.setConnectionFactory(jedisConnectionFactory());
return template;
}
我的端点返回 ResponseEntity:
@RequestMapping(value = "/foo")
public ResponseEntity<String> foo() {
return new ResponseEntity<>("bar", HttpStatus.OK);
}
错误日志:
Could not read JSON: Can not construct instance of org.springframework.http.ResponseEntity: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: [B@74297a01; line: 1, column: 137] (through reference chain: br.com.stilingue.cloudutilities.cache.CacheItem["value"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not construct instance of org.springframework.http.ResponseEntity: no suitable constructor found, can not deserialize from Object value (missing default constructor or creator, or perhaps need to add/enable type information?)
at [Source: [B@74297a01; line: 1, column: 137] (through reference chain: br.com.stilingue.cloudutilities.cache.CacheItem["value"])
在反序列化对象时出现问题,有谁知道我该怎么办?
【问题讨论】:
-
我也有同样的问题。你找到解决办法了吗?
-
找到解决方案了吗?
-
很遗憾没有:/
标签: spring-boot redis spring-data-redis