jackson日期格式转换LocalDateTime异常 JSON parse error: Cannot deserialize value of type `java.time.LocalDate

异常如下

JSON parse error: Cannot deserialize value of type `java.time.LocalDateTime` from String "2023-10-08": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2023-10-08' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 2023-10-08 of type java.time.format.Parsed; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.time.LocalDateTime` from String "2023-10-08": Failed to deserialize java.time.LocalDateTime: (java.time.format.DateTimeParseException) Text '2023-10-08' could not be parsed: Unable to obtain LocalDateTime from TemporalAccessor: {},ISO resolved to 2023-10-08 of type java.time.format.Parsed

首先一点,看对应的字段上是否有

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")

如果有,在 filter 或 aop 层次看请求参数中的日期格式。

不排除是请求参数格式与接收的类型冲突。

例如,传的日期是 2023-10-08 却用 LocalDateTime 解析是不行的,应该使用 LocalDate,确保日期格式、日期类型对应起来。

有一个比较好的办法,就是使用Unix时间戳传long类型的日期不会有这些问题,如果有时区,另外加上时区即可。

https://www.cnblogs.com/seanstudy/p/15848259.html

https://www.cnblogs.com/liuyiyuan/p/16379868.html

https://blog.csdn.net/m0_61871870/article/details/129923962 

你可能感兴趣的:(java,python,开发语言)