我正在组织中创建自定义缓存架构,并且必须序列化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"])
问题发生在反序列化对象时,是否有人知道我能做什么?
答案 0 :(得分:0)
尝试在return语句中添加类型信息:
localhost:3000/admins/sign_up