users@jersey.java.net

Re: [Jersey] Parsing unix timestamp in JSON

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 28 Jan 2010 16:08:32 +0100

Hi Chris,

I presume you are using JAXB with fields or bean properties of the
Date type?

If so you need to override the default JAXB support for marshaling and
unmarshaling date. The following link will help:

   http://blogs.sun.com/CoreJavaTechTips/entry/exchanging_data_with_xml_and

   Search for the string "DateAdapter".

Paul.

On Jan 27, 2010, at 7:44 PM, Chris Carrier wrote:

> 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!