Redis使用LocalDateTime报错问题

SpringBoot整合Redis时,使用LocalDate以下报错

org.springframework.data.redis.serializer.SerializationException: Could not read JSON: Cannot construct instance of `java.time.LocalDateTime` 
(no Creators, like default constructor, exist): no String-argument constructor/factory method to deserialize from String value ('2021-03-06T11:27:13')

原因在于 localDateTime 无法完成反序列化,这里有2种解决方法。

1、直接在字段上面加两个注解即可

  
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    private LocalDateTime createTime;

2、在 Redis 配置类加上如下代码。

RedisConfig.java 

原文地址:https://www.cnblogs.com/dragon-lan/p/15536225.html