sangmingming / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

support java.sql.Date and Timestamp types #134

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Apparently these two types are not supported in the DefaultTypeAdapters
(v1.3). Would be very useful if they are provided out of the box, and saves
users from writing custom serializer/deserializer.

Thanks

Original issue reported on code.google.com by HSajja...@gmail.com on 8 Jul 2009 at 5:31

GoogleCodeExporter commented 9 years ago
We are concerned about introducing a dependency on the java.sql package on 
Gson. While I understand that 
java.sql is part of all Java runtimes, there could be Java like runtimes that 
dont support these packages.

We should publish the converters for these classes at this page though: 
http://sites.google.com/site/gson/gson-type-adapters-for-common-classes-1

Original comment by inder123 on 23 Sep 2009 at 7:07

GoogleCodeExporter commented 9 years ago
Deferred for consideration in a future release.

Original comment by inder123 on 29 Sep 2009 at 6:10

GoogleCodeExporter commented 9 years ago
Perhaps the fact that java.sql.Date and java.sql.Timestamp are subclasses of
java.util.Date would allow you to avoid explicit dependencies... ? I haven't 
looked
at the code so don't know if this would work or not.

Original comment by archie.c...@gmail.com on 3 Dec 2009 at 4:56

GoogleCodeExporter commented 9 years ago
Fixed in r513 by adding explicit support for java.sql Date and Timestamp. I 
could not 
avoid the explicit dependencies though, but decided that java.sql dependency 
may not 
be all that bad.

Original comment by inder123 on 4 Dec 2009 at 1:22

GoogleCodeExporter commented 9 years ago
Given java.sql.Timestamp allows for more precise time tracking (ie: nano 
seconds), was wondering how one would go about converting a nano/micro second 
string timestamp into a java.sql.Timestamp using GSON, ie:

{
 "microsecond_date": "2012-10-24T00:25:42.000000Z",
 "nanosecond_date": "2012-10-24T00:25:42.000000000Z"
}

Given GSON uses ISO 8601 formatting which accepts decimal positions on any of 
the time elements (http://en.wikipedia.org/wiki/ISO_8601#Times), I'm wondering 
if there would be a way without having to write my own 
serialization/deserialization logic to parse the string out given the impl 
provided by DefaultDateTypeAdapter relies on SimpleDateFormat which doesn't 
support more than 3 decimal positions.

Original comment by roberto.andrade on 14 Aug 2013 at 10:48

GoogleCodeExporter commented 9 years ago
I am also curious if it can be done without writing a custom deserializer. 

Original comment by Rob.Isak...@gmail.com on 3 Dec 2013 at 9:36