users@jersey.java.net

Re: [Jersey] Parsing unix timestamp in JSON

From: Chris Carrier <ctcarrier_at_gmail.com>
Date: Thu, 28 Jan 2010 09:18:59 -0800

Actually I had configured Jeresy to just use the Jackson provider
(org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider) because JAXB was
behaving even stranger with my date format. Thanks for pointing out the
link though I'll give that a shot.

But out of curiousity if I'm using Jackson directly why wouldn't it be able
to handle a Unix timestamp like I have below? I thought that was it's
default behavior. The strange thing is if I take the quotation marks off of
the timestamp value it works fine. But with the quotes it thinks it's a
String and not a long and tries to parse it as such.

Thanks!
Chris

On Thu, Jan 28, 2010 at 7:08 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:

> 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!
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
>