异常如下

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,确保日期格式、日期类型对应起来。

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

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

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐