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

在实体类中时间类型使用LocalDateTime时,存入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’)

解决方案:
LocalDateTime属性上加一下两个注解即可:

@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonSerialize(using = LocalDateTimeSerializer.class)

你可能感兴趣的:(防踩坑专栏,redis,java)