Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support java.sql.Date and Timestamp types #134

Closed
GoogleCodeExporter opened this issue Mar 19, 2015 · 12 comments
Closed

support java.sql.Date and Timestamp types #134

GoogleCodeExporter opened this issue Mar 19, 2015 · 12 comments

Comments

@GoogleCodeExporter
Copy link

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 [email protected] on 8 Jul 2009 at 5:31

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

Deferred for consideration in a future release.

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

  • Added labels: Milestone-Release1.5

@GoogleCodeExporter
Copy link
Author

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 [email protected] on 3 Dec 2009 at 4:56

@GoogleCodeExporter
Copy link
Author

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

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

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
Copy link
Author

I am also curious if it can be done without writing a custom deserializer. 

Original comment by [email protected] on 3 Dec 2013 at 9:36

@sbernard31
Copy link

Hi,
We use gson in Leshan. This is an implementation of lightweight M2M protocol.
We have a Server and a Client implementation.
We aim compact profile of java for the Client. Unfortunately gson has dependency to java.sql.* so we need to use the compact2 profile instead of the compact1 profiles which is ~40% bigger.
See leshan issue

@davidbro-in
Copy link

@sbernard31, did you find an alternative to use compact1 profile?

@sbernard31
Copy link

No, we didn't do anything for now, but we consider using https://github.com/ralfstx/minimal-json

@henryju
Copy link

henryju commented Jun 14, 2018

With Java 9 and modularity, it means we have to add an extra dependency on java.sql module when using Gson.

@gudenau
Copy link

gudenau commented Aug 6, 2018

Yeah, the module thing is a bit of a pain. Every time I requires gson; I also need to requires java.sql;.

Would be nice if this supported project Jigsaw in a more complete manor.

@coded9
Copy link

coded9 commented Sep 5, 2018

Hey ! Is there any hotfix for 1.4 version for sql date and time types ??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants