{"id":500,"date":"2015-10-22T21:36:13","date_gmt":"2015-10-22T21:36:13","guid":{"rendered":"http:\/\/installingcats.com\/?p=500"},"modified":"2015-10-22T21:36:13","modified_gmt":"2015-10-22T21:36:13","slug":"retrofit-error-415-400-object-date-field","status":"publish","type":"post","link":"https:\/\/installingcats.com\/2015\/10\/22\/retrofit-error-415-400-object-date-field\/","title":{"rendered":"Retrofit error 415 400 object with Date field Fix @JsonFormat annotation"},"content":{"rendered":"

Retrofit error 415 or error 400 on an object with a Date field can be fixed by using @JsonFormat annotation with the proper date pattern format specified in the annotation.<\/p>\n

java.util.Date toString() (for my locale\/region) returns a string date format of MMM dd, yyyy hh:mm:ss aa<\/p>\n

Example: Oct 22, 2015 11:09:55 PM<\/p>\n

For Retrofit \/ Jackson to serialize \/ deserialize a date (java.util.Date) properly, you must annotate your Date fields with the corresponding date pattern:<\/p>\n

@JsonFormat(shape= JsonFormat.Shape.STRING, pattern = \"MMM dd, yyyy hh:mm:ss aa\")<\/pre>\n

Pay special attention to the uppercase \/ lowercase lettering of each date part. \u00a0Two digit date of month must be LOWERCASE (i.e. “dd” not “DD”). \u00a0Otherwise it will be interpreted as a date of year<\/em> which can be three digits. \u00a0(I was getting bizarre JSON serialization JSON deserialization results such as Oct 22 becoming Dec 362 by having the wrong case on my date part of the date format (i.e. “DD”.)<\/p>\n

For the full list of date format parts that Jackson\u00a0(fasterxml) uses see:<\/p>\n

http:\/\/docs.oracle.com\/javase\/1.5.0\/docs\/api\/java\/text\/SimpleDateFormat.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

Retrofit error 415 or error 400 on an object with a Date field can be fixed by using @JsonFormat annotation with the proper date pattern format specified in the annotation. java.util.Date toString() (for my locale\/region) returns a string date format of MMM dd, yyyy hh:mm:ss aa Example: Oct 22, 2015 11:09:55 PM For Retrofit \/ […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[28,29,248],"tags":[249,250],"_links":{"self":[{"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/posts\/500"}],"collection":[{"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/comments?post=500"}],"version-history":[{"count":0,"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/posts\/500\/revisions"}],"wp:attachment":[{"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/media?parent=500"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/categories?post=500"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/installingcats.com\/wp-json\/wp\/v2\/tags?post=500"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}