首页 /  技术专区  /  Java 宽屏模式 >

解决日期转换异常 JSON parse error: Cannot deserialize value of type `java.util.Date` from String

08-10 15:15:51.916 ERROR 9996 [XNIO-1 task-1] c.r.f.w.e.GlobalExceptionHandler(GlobalExceptionHandler.java:76): JSON parse error: Cannot deserialize value of type `java.util.Date` from String "2021-08-10 13:58:17": not a valid representation (error: Failed to parse Date value '2021-08-10 13:58:17': Cannot parse date "2021-08-10 13:58:17": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null)); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2021-08-10 13:58:17": not a valid representation (error: Failed to parse Date value '2021-08-10 13:58:17': Cannot parse date "2021-08-10 13:58:17": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null))
 at [Source: (PushbackInputStream); line: 1, column: 142] (through reference chain: org.gl.space.domain.bo.TeacherBo["birthDate"])
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize value of type `java.util.Date` from String "2021-08-10 13:58:17": not a valid representation (error: Failed to parse Date value '2021-08-10 13:58:17': Cannot parse date "2021-08-10 13:58:17": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null)); nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2021-08-10 13:58:17": not a valid representation (error: Failed to parse Date value '2021-08-10 13:58:17': Cannot parse date "2021-08-10 13:58:17": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null))
 at [Source: (PushbackInputStream); line: 1, column: 142] (through reference chain: org.gl.space.domain.bo.TeacherBo["birthDate"])
	
Caused by: com.fasterxml.jackson.databind.exc.InvalidFormatException: Cannot deserialize value of type `java.util.Date` from String "2021-08-10 13:58:17": not a valid representation (error: Failed to parse Date value '2021-08-10 13:58:17': Cannot parse date "2021-08-10 13:58:17": while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSZ', parsing fails (leniency? null))
 at [Source: (PushbackInputStream); line: 1, column: 142] (through reference chain: org.gl.space.domain.bo.TeacherBo["birthDate"])

日期转换异常 JSON parse error: Cannot deserialize value of type `java.util.Date` from String

解决办法:加上注解@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")

image.png

@ApiModelProperty(value = "初领日期")
@JsonFormat(locale = "zh", timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
private String firstCertDate;




头像
0/200
图片验证码