views:

52

answers:

2

I have a date in a json string (returned from an ASP.NET rest service) that looks like this: "created": "/Date(1277931782420-0700)/"

Jackson is not able to parse this date. I can write my own date format and pass it in to mapper.getDeserializationConfig().setDateFormat(); but i was wondering if there is an easier/better way to do this...

A: 

You can use code Date constructor to deserialize Date from the form

var d = new Date(1277931782420-0700);
alert("Year:" + d.getFullYear() + ", Month:" + d.getMonth() +
      ", Date:" + d.getDate());

If you use MicrosoftAjax.debug.js (Sys.Serialization.JavaScriptSerializer.deserialize) to deserialize data you will have no problems. You can look at the code of Sys.Serialization.JavaScriptSerializer.deserialize to do this yourself.

Oleg
i am trying to do this in java... not C# or javascript. jackson is a java library. to give some context, this is in an android app.
Ben
A: 

I think defining date format is a reasonable way to do it. Alternatively you could define your own JsonDeserializer, register it, but it's not any simpler way (but may be more powerful if you need more complex parsing).

StaxMan