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
注解。文章来源:https://www.toymoban.com/news/detail-491284.html
代码定位:(第一次序列化时调用,后续从缓存中取)
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文章来源地址https://www.toymoban.com/news/detail-491284.html
到了这里,关于SerializationException: Could not read JSON: Unrecognized field的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!