I'm receiving .NET's DateTime
object as json string through my asmx webservice and trying to parse it with help of gson library. But seems like there's no support to parse .net style DateTime.
How can i parse it easily into java's Date
object using Gson without much hassle?
the string i receive is like:
"DateOfBirth":"\/Date(736032869080)\/"
P.S. I would not like to make any modifications at server side to receive DateTime as a Long value
Like this:
Or use this example instead & follow the "Dealing with WCF Microsoft JSON Dates" chapter.
I've implemented a GsonHelper, which helps deserializing and serializing .NET
DateTime
format from JSON using GSON. Usage:This is the helper class:
Note: works for two formats:
/Date(1362853251000)/
and/Date(1362853251000+0000)/
. Helper have to be tuned for other formats with time defined.To manually convert a .NET JSON date to a JodaTime DateTime object (native Java type similar), you can also use a regex:
I've implemented this, interoperable with .NET WCF DateTime Json format. With Time Zone
Without TimeZone UTC
First you need add to your project
1) Google Gson Library GSON
2) JodaTime library JodaTime Use prior to JDK8.
Main class
DateTime Serializer
DateTime Deserializer
Sample class to Serialize
and my main/test class
My Util/Helper Class
Note: *
*
Dont Know...I had tryed all above.. but didn't work for me. finally I have come with this solution :)
when you get string from json object string will get like : "/Date(1373543393598+0200)/". but if You will see on result string which is comming from server will look like this: {"respDateTime":"/Date(1373267484478+0200)/"}