Java教程

redis序列化LocalDateTime时报错 报错信息:Could not read JSON: Cannot construct instance of `java.time.LocalDate

本文主要是介绍redis序列化LocalDateTime时报错 报错信息:Could not read JSON: Cannot construct instance of `java.time.LocalDate,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

在SSM中,向Redis中存入信息后,在取出的时候出现

org.springframework.data.redis.serializer.SerializationException:
Could not read JSON: Cannot construct instance of java.time.LocalDateTime (no Creators, like default construct,exist):
no String-argument constructor/factory method to deserialize from String value (‘2019-11-13 18:05:32’)

错误,是因为序列化时失败,在失败的字段,也就是实体类中时间属性,添加上以下注解

 

@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)
这篇关于redis序列化LocalDateTime时报错 报错信息:Could not read JSON: Cannot construct instance of `java.time.LocalDate的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!