报错 Cannot construct instance of `java.time.LocalDate` LocalDateTime

发布时间 2023-07-06 14:54:56作者: StormArcita

原因:报错的原因就是导入了JacksonObjectMapper对象映射器,导致不知道怎么将LocalDateTime转换成Json类型的数据了,在没有导入使用JacksonObjectMapper的时候是不会报错的。

解决方式:指定LocalDateTime类型的数据如何进行序列化就好了,给实体类中LocalDateTime的属性加上注解就可以了:

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