提交String類(lèi)型的日期yyyy/MM/報(bào)錯(cuò)粉洼,可以通過(guò)如下方式解決這個(gè)問(wèn)題
使用注解@JsonFormat配置格式解決下面的報(bào)錯(cuò)
@JsonFormat(pattern = "yyyy/MM/dd")
private Date acDate;
請(qǐng)求報(bào)文
{
"acDate":"2020/08/24"
}
報(bào)錯(cuò)日志(沒(méi)有配置@JsonFormat前)
2020-08-24 16:20:18.198 WARN 2036 --- [nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.http.converter.HttpMessageNotReadableException:
JSON parse error: Cannot deserialize value of type `java.util.Date` from String "2020/08/24":
not a valid representation (error: Failed to parse Date value '2020/08/24':
Cannot parse date "2020/08/24": not compatible with any of standard forms
("yyyy-MM-dd'T'HH:mm:ss.SSSX", "yyyy-MM-dd'T'HH:mm:ss.SSS", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"));
nested exception is com.fasterxml.jackson.databind.exc.InvalidFormatException:
Cannot deserialize value of type `java.util.Date` from String "2020/08/24":
not a valid representation (error: Failed to parse Date value '2020/08/24':
Cannot parse date "2020/08/24": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSX", "yyyy-MM-dd'T'HH:mm:ss.SSS", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))
at [Source: (PushbackInputStream); line: 4, column: 12] (through reference chain: org.ysy.study.bcdb.dto.agreement.AgreementDTO["acDate"])]