gpt4 book ai didi

spring-boot - 如何反序列化 Redis 的 ResponseEntity?

转载 作者:IT王子 更新时间:2023-10-29 06:02:42 24 4
gpt4 key购买 nike

我正在我的组织中创建自定义缓存架构,并且必须序列化 ResponseEntity 对象。我正在使用 GenericJackson2JsonRedisSerializer 来序列化对象,但是当它是 ResponseEntity 时它不接受。

我使用 Jackson Serializer 的自定义 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"])

问题发生在反序列化对象时,有谁知道我能做什么?

最佳答案

尝试在返回语句中添加类型信息:

return new ResponseEntity<String>("bar", HttpStatus.OK);

关于spring-boot - 如何反序列化 Redis 的 ResponseEntity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46779961/

24 4 0
文章推荐: symfony - 失去与 Redis 服务的连接
文章推荐: javascript - d3.js 使用极坐标绘制元素
文章推荐: javascript - jQuery select2 重新格式化