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

必要なタイプに[java.lang.Stringで]型のプロパティ値を変換に失敗しました、私は文字列の上に投稿したいjava.time.LocalDateとして、JSONの日付が、私のように400不正なリクエストを受け付けておりますエラー。ある人がここで助けてもらえますか?私は@JsonFormatを使用しましたが、それはどちらも役に立ちませんでした。は[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

この1の複製のようなあなたの日付プロパティに

@DateTimeFormat(iso = DateTimeFormat.ISO.DATE) 
関連する問題