json反序列化失败
来源:8-7 文件上传组件的使用

RichardChang
2021-02-16
在修改小节数据保存时 时间格式不正确 报错如下:
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String "2020-12-06T07:00:51.000+0000": expected format "yyyy-MM-dd HH:mm:ss"; nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2020-12-06T07:00:51.000+0000": expected format "yyyy-MM-dd HH:mm:ss"
at [Source: (PushbackInputStream); line: 1, column: 141] (through reference chain: com.course.server.dto.SectionDto["createdAt"])]
在dto检查 没有问题 创建时间和修改时间都有注解
@JsonFormat(locale="zh", timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss")
3回答
-
按理只需要在DTO的日期里加个注解就可以了,如下:
你试试在前端把日期字段显示出来看看是什么样,应该要是上面的yyyy-MM-dd HH:mm:ss格式
042021-03-09 -
RichardChang
提问者
2021-03-01
@JsonFormat(pattern="yyyy-MM-dd'T'HH:mm:ss",timezone = "GMT+8")
解决!
00 -
甲蛙
2021-02-19
这个报错意思是,期望的格式是yyyy-MM-dd HH:mm:ss,而你传进来是2020-12-06T07:00:51.000+0000,你把这个时间在前端格式化成yyyy-MM-dd HH:mm:ss格式的字符串,再传到后端试试
022021-03-01
相似问题