I've got some JSON that has timestamps in seconds (i.e. a Unix timestamp):
{"foo":"bar","timestamp":1386280997}
Asking Jackson to deserialize this into an object with a DateTime field for the timestamp results in 1970-01-17T01:11:25.983Z
, a time shortly after the epoch because Jackson is assuming it to be in milliseconds. Aside from ripping apart the JSON and adding some zeros, how might I get Jackson to understand the seconds timestamp?
A very similar approach to that of @DrewStephens's which uses the Java SE
TimeUnit
API (introduced inJDK1.5
) instead of plain String concatenation and is thus (arguably) a little bit cleaner and more expressive:Specifying your custom deserializer (
UnixTimestampDeserializer
) on the affectedDate
field(s):I wrote a custom deserializer to handle timestamps in seconds (Groovy syntax).
And then I annotated my POGO to use that for the timestamp:
edit: vivek-kothari suggestion