I have a Date format coming from API like this:
"start_time": "2015-10-1 3:00 PM GMT+1:00"
Which is YYYY-DD-MM HH:MM am/pm GMT timestamp. I am mapping this value to a Date variable in POJO. Obviously, its showing conversion error.
I would like to know 2 things:
- What is the formatting I need to use to carry out conversion with Jackson? Is Date a good field type for this?
- In general, is there a way to process the variables before they get mapped to Object members by Jackson? Something like, changing the format, calculations, etc.
I want to point out that setting a
SimpleDateFormat
like described in the other answer only works for ajava.util.Date
which I assume is meant in the question. But forjava.sql.Date
the formatter does not work. In my case it was not very obvious why the formatter did not work because in the model which should be serialized the field was in fact ajava.utl.Date
but the actual object ended up beeing ajava.sql.Date
. This is possible becauseSo this is actually valid
So if you are wondering why your Date field is not correctly formatted make sure that the object is really a
java.util.Date
.Here is also mentioned why handling
java.sql.Date
will not be added.