Jackson 2.3.2: a problem with date deserialization, despite the fact that the date format is for ObjectMapper

I use rest easy and want to serialize and deserialize dates.

After creating my json provider, Serializing works fine, but deserialization still doesn't work.

My JsonProvider class:

@Provider @Produces(MediaType.APPLICATION_JSON) public class JsonProvider extends JacksonJaxbJsonProvider { public JsonProvider() { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); mapper.setDateFormat("dd MMM, yyyy hh:mm:ss a"; super.setMapper(mapper); } } 

Entry Date : September 09, 2014 11:00:00 AM

Error: com.fasterxml.jackson.databind.exc.InvalidFormatException: cannot create java.util.Date instance from String value '09 Sep, 2014 11:00:00 AM ': invalid view (Error: could not parse date value '09 Sep, 2014 11:00:00 AM ': Unable to parse the date "September 09, 2014 11:00:00 AM" : not compatible with any of the standard ones ("yyyy-MM-dd'T'HH: mm: ss. SSSZ "," yyyy-MM-dd'T'HH: mm: ss.SSS'Z '", EEE, dd MMM yyyy HH: mm: ss zzz", "yyyy-MM-dd))

I came across this workaround, but if I use this, then I have to annotate each date field in my application, which, in my opinion, is an overhead.

I cannot understand what I am doing wrong.

Any help would be appreciated.

Thanks.

+7
json datetime deserialization resteasy
source share
1 answer

I got the same error, this solved my problem

mapper.setDateFormat(myDateFormat)

http://wiki.fasterxml.com/JacksonFAQDateHandling

+3
source share

All Articles