DateTime Parsing error

2,484 views
Skip to first unread message

Giuseppe

unread,
Jul 16, 2012, 2:43:14 AM7/16/12
to googl...@googlegroups.com
I am very new to Gson and probably the answer to my problem is very simple.

I have a WCF service that return a custom object serialized in Json by JSON.NET like this:

{"$id":"1","ID":261,"Email":"custom...@gmail.com","DeviceID":"08ebee0b-cfcd-4fb4-9d74-b6571a672134","Country":"Italia","IntallationData":"2012-07-16T08:41:53"}


The code I am using to deserialize in Android JAVA client is too simple:

 Users new_u = gson.fromJson(theString, Users.class);
 
The error is:

com.google.gson.JsonSyntaxException: 2012-07-16T08:35:03
java.text.ParseException: Unparseable date: "2012-07-16T0 8:35:03 " (at offset 19)


Probably I need some help with a custom deserialization???






Inderjeet Singh

unread,
Jul 16, 2012, 3:07:10 AM7/16/12
to googl...@googlegroups.com
Look at GsonBuilder.setDateFormat(String pattern)


On Sunday, July 15, 2012 11:43:14 PM UTC-7, Giuseppe wrote:
I am very new to Gson and probably the answer to my problem is very simple.

I have a WCF service that return a custom object serialized in Json by JSON.NET like this:

{"$id":"1","ID":261,"Email":"custome...@gmail.com","DeviceID":"08ebee0b-cfcd-4fb4-9d74-b6571a672134","Country":"Italia","IntallationData":"2012-07-16T08:41:53"}

Giuseppe

unread,
Jul 16, 2012, 3:26:53 AM7/16/12
to googl...@googlegroups.com
Thank you, this work like charm !
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ss").create();
Reply all
Reply to author
Forward
0 new messages