异常信息:JSON parse error: Cannot deserialize value of type `java.util.Date` from String "2022-12-15 12:28:21": not a valid representation (error: Failed to parse Date value '2022-12-15 12:28:21': Cannot parse date "2022-12-15 12:28:21": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX', parsing fails (leniency? null)); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2022-12-15 12:28:21": not a valid representation (error: Failed to parse Date value '2022-12-15 12:28:21': Cannot parse date "2022-12-15 12:28:21": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX', parsing fails (leniency? null))
在测试过程中发现从其他服务获取的日期数据(字符串类型)无法转为date,最后将注解换为@JsonFormat解决
解决办法:
将@DateTimeFormat(pattern = “yyyy-MM-dd HH-mm-ss”)
换为@JsonFormat( timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
在测试中遇到一个异常,即从其他服务获取的日期字符串(2022-12-1512:28:21)无法转换为Date对象,因为格式不匹配。原始的@DateTimeFormat注解不适用。通过将注解改为@JsonFormat,并指定timezone为GMT+8,pattern为yyyy-MM-ddHH:mm:ss,成功解决了这个问题。
1068

被折叠的 条评论
为什么被折叠?



