org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Unrecognized field
原因:对象中如果有setXXX
或getXXX
方法,或返回值为Boolean
或boolean
的isXXX
方法,但没有对应的XXX
字段,使用Jackson2JsonRedisSerializer
序列化后json中会有对应的key值XXX
,从而会导致反序列化失败。
解决办法:在类加上注解@JsonIgnoreProperties(ignoreUnknown = true)
忽略实体中没有对应的json的key值,或者在set、get或is开头的方法上加上@JsonIgnore
注解。
代码定位:(第一次序列化时调用,后续从缓存中取)
DefaultValueOperations 235 set
AbstractOperations 127 rawValue
org.springframework.data.redis.serilizer.Jackson2JsonRedisSerializer 86 serilizer
com.fasterxml.jackson.databind.ObjectMapper 3428 writeValueAsBytes
ObjectMapper 4094 _configAndWriteValue
DefaultSerializerProvider 308 serializeValue
SerializerProvider 713 findTypedValueSerializer
SerializerProvider 510 findValueSerializer
SerializerProvider 1336 _createAndCacheUntypedSerializer 此处将序列化器加入缓存
SerializerProvider 1388 _createUntypedSerializer
BeanSerializerFactory 165 createSerializer
BeanSerializerFactory 216 _createSerializer2
BasicSerializerFactory 346 findSerializerByAnnotations
BasicBeanDescription findJsonValueAccessor 252
POJOPropertiesCollector getJsonValueAccessor 196
POJOPropertiesCollector collectAll() 309
POJOPropertiesCollector _addMethods 533
POJOPropertiesCollector _addGetterMethod 583、586
BeanUtil okNameForRegularGetter 38
BeanUtil okNameForIsGetter 69