JSON Serializing date in a custom format (Can not construct instance of java.util.Date from String value)

后端 未结 6 1425
野的像风
野的像风 2020-12-03 07:01
could not read JSON: Can not construct instance of java.util.Date from String 
value \'2012-07-21 12:11:12\': not a valid representation(\"yyyy-MM-dd\'T\'HH:mm:ss.SS         


        
6条回答
  •  天涯浪人
    2020-12-03 07:42

    Annotate your created_date field with the JsonFormat annotation to specify the output format.

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = TimeZone.getDefault(), locale = Locale.getDefault())
    

    Note that you may need to pass in a different Locale and TimeZone if they should be based on something other than what the server uses.

    You can find out more information in the docs.

提交回复
热议问题