JSON parse error: Cannot deserialize value of type `java.sql.Timestamp` from String“” 的解决方法

用postman这样传参数的时候出现了这样的bug,但是把2020-01-01改成数字串
631180800000就不会报错了。
JSON parse error: Cannot deserialize value of type `java.sql.Timestamp` from String“” 的解决方法_第1张图片

WARN 64728 --- [nio-9000-exec-5] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException: : not a valid representation (error: Failed to parse Date value '2020-1-1': Cannot parse date "2020-1-1": while it seems to fit format 'yyyy-MM-dd', parsing fails (leniency? null)); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.sql.Timestamp` from String "2020-1-1": not a valid representation (error: Failed to parse Date value '2020-1-1': Cannot parse date "2020-1-1": while it seems to fit format 'yyyy-MM-dd', parsing fails (leniency? null))
 at [Source: (PushbackInputStream); line: 2, column: 12] (through reference chain: com.mss.mss_server.bean.UserInfo["birth"])]

解决方案
在对应的实体内添加代码就可以了:

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern="yyyy-MM-dd")

JSON parse error: Cannot deserialize value of type `java.sql.Timestamp` from String“” 的解决方法_第2张图片

原因

birth变量使用了字符串类型,接口接收参数后将该字符串转为日期时,发生错误,项目中使用JsonFormat来处理json数据。

你可能感兴趣的:(SpringBoot)