users@jersey.java.net

Parsing unix timestamp in JSON

From: Chris Carrier <ctcarrier_at_gmail.com>
Date: Wed, 27 Jan 2010 10:44:45 -0800

Hey folks,

Sorry for anyone who gets this twice. I accidentally sent it to the dev
list when i meant the user list. Anyway...

I'm trying to integrate Jersey into a fairly simple POST method. At this
moment I'm just trying to get the JSON request body properly marshalled into
the object. My current problem revolves around parsing timestamps. So my
request looks something like:

{
  "version": "1.0",
  "size": 1,
  "links": [{
    "key": "abcdef",
    "createdDate": "1264616643",
    "updatedDate": "1264616643",
    }
  ]}

Where createdDate and updatedDate are formatted as Unix timestamps. This is
the default behavior of the Jackson JSON parser but when i try this with
Jersey the date is completely marfled. For instance the above dates are
parsed into a date that looks like "Sun Jun 28 19:08:16 PDT 95508544" which
is a completely nonsense date. So how can I configure this behavior? I
can;t find any mention of people having this problem which is surprising.
Right now I can't even find a way to access the parsers to configure them.
I have a JAXBContextResolver but all i can seem to configure there is the
JSON format on a document level. Nothing as specific as date format. Any
advice?

Thanks!