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)
上一篇:Java时间


下一篇:MyBatis-Plus自动填充创建时间和更新时间