小编Cha*_*wri的帖子

无法将类型 [java.lang.String] 的属性值转换为所需类型 [java.time.LocalDate]

{
"toDepartureDate": "2016-12-28",
"fromDepartureDate": "2016-12-28"
}
Run Code Online (Sandbox Code Playgroud)

我想将上面的字符串日期以 json 格式发布java.time.LocalDate,但我收到 400 Bad Request 作为错误。有人可以帮忙吗?我已经使用过@JsonFormat,但它也没有帮助我。

@JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd",timezone = "GMT+5:30")

private LocalDate fromDepartureDate;

@JsonFormat(shape=JsonFormat.Shape.STRING,pattern="yyyy-MM-dd",timezone = "GMT+5:30")
private LocalDate toDepartureDate;

{
  "timestamp": 1482942147246,
  "status": 400,
  "error": "Bad Request",
  "exception": "org.springframework.validation.BindException",
  "errors": [
    {
      "codes": [
        "typeMismatch.flightReportSearchDto.fromDepartureDate",
        "typeMismatch.fromDepartureDate",
        "typeMismatch.java.time.LocalDate",
        "typeMismatch"
      ],
      "arguments": [
        {
          "codes": [
            "flightReportSearchDto.fromDepartureDate",
            "fromDepartureDate"
          ],
          "arguments": null,
          "defaultMessage": "fromDepartureDate",
          "code": "fromDepartureDate"
        }
      ],
      "defaultMessage": "Failed to convert property value of type [java.lang.String] to required type [java.time.LocalDate] for property …
Run Code Online (Sandbox Code Playgroud)

java json jackson spring-boot

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

jackson ×1

java ×1

json ×1

spring-boot ×1