2016-12-28 96 views
0
{ 
"toDepartureDate": "2016-12-28", 
"fromDepartureDate": "2016-12-28" 
} 

我要張貼上面的字符串在JSON作爲java.time.LocalDate日期,但我收到400錯誤的請求爲錯誤。有人能幫忙嗎?我用@JsonFormat,但它也沒有幫助我。未能類型的屬性值轉換[java.lang.String中]所需類型[java.time.LocalDate]

@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 'fromDepartureDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@com.fasterxml.jackson.annotation.JsonFormat java.time.LocalDate] for value '2016-12-28'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2016-12-28]", 
     "objectName": "flightReportSearchDto", 
     "field": "fromDepartureDate", 
     "rejectedValue": "2016-12-28", 
     "bindingFailure": true, 
     "code": "typeMismatch" 
    }, 
    { 
     "codes": [ 
     "typeMismatch.flightReportSearchDto.toDepartureDate", 
     "typeMismatch.toDepartureDate", 
     "typeMismatch.java.time.LocalDate", 
     "typeMismatch" 
     ], 
     "arguments": [ 
     { 
      "codes": [ 
      "flightReportSearchDto.toDepartureDate", 
      "toDepartureDate" 
      ], 
      "arguments": null, 
      "defaultMessage": "toDepartureDate", 
      "code": "toDepartureDate" 
     } 
     ], 
     "defaultMessage": "Failed to convert property value of type [java.lang.String] to required type [java.time.LocalDate] for property 'toDepartureDate'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@com.fasterxml.jackson.annotation.JsonFormat java.time.LocalDate] for value '2016-12-29'; nested exception is java.lang.IllegalArgumentException: Parse attempt failed for value [2016-12-29]", 
     "objectName": "flightReportSearchDto", 
     "field": "toDepartureDate", 
     "rejectedValue": "2016-12-29", 
     "bindingFailure": true, 
     "code": "typeMismatch" 
    } 
    ] 

} 
+2

象這樣的副本:http://stackoverflow.com/questions/28802544/java-8-localdate-jackson-format –

回答

0

添加在你的日期財產

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) 
相關問題