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

Make java.sql.Date serializer default to same output as java.util.Date #2405

Closed
cowtowncoder opened this issue Aug 4, 2019 · 7 comments
Closed
Labels
3.x Issues to be only tackled for Jackson 3.x, not 2.x
Milestone

Comments

@cowtowncoder
Copy link
Member

(note: follow-up to #2403 )

Currently (in 2.x) java.sql.Date is serialized as String using value.toString(), which uses local timezone. This is different from other date/time types, but due to backwards compatibility issues, change can only be done in 3.0.

@cowtowncoder cowtowncoder added 3.x Issues to be only tackled for Jackson 3.x, not 2.x ACTIVE labels Aug 4, 2019
@michael-o
Copy link

Strongly support this to treat it as Instant.

@cowtowncoder
Copy link
Member Author

One challenge is that handling itself will still be distinct (at least according to current plans) from JDK8 date/time. But the idea of making it work like Instant is of course what the goal would be.

At first tho it might be sort of as simple as making serializer extend same base class as that for java.util.Date, if that's not yet the case.

@michael-o
Copy link

Please also note that although java.sql.Date extends java.util.Date it applies a different format as defined by some SQL standard (a deviation of ISO 8601) and has only day or second precision.

@cowtowncoder
Copy link
Member Author

@michael-o I was aware of different default representation (via toString()), but had forgotten about granularity limitations. Come to think of it, not even quite sure how it should work; inheritance here is wrong of course but not much we can do about it.

But just to make sure: is your suggestion to serialize it (when using String representation, not timestamp), as same ISO-8601 as what would be used for JSR-310 (java 8) date/time Instant?
(basically ignore possibly implied semantics of Date-only / Time-only)
That seems like reasonable approach (if not the only possibility), just want to make sure I did not misunderstand.

@michael-o
Copy link

But just to make sure: is your suggestion to serialize it (when using String representation, not timestamp), as same ISO-8601 as what would be used for JSR-310 (java 8) date/time Instant?

For java.util.Date and java.util.Calendar -- yes, use the counterparts from JSR 310.

(basically ignore possibly implied semantics of Date-only / Time-only)

Here is the exception, anything ìn java.sql.* must be treated separately because those formats are well defined and must not be changed by default -- along with the loss of precision.

@cowtowncoder cowtowncoder changed the title Make java.sql.Date serializer use standard time (UTC), not local timezone in 3.x Make java.sql.Date serializer default to same output as java.util.Date Feb 4, 2021
@cowtowncoder
Copy link
Member Author

Changed the definition a bit: change handling of java.sql.Date to be identical to java.util.Date (but overridable with format separately).

Also starting to think of whether to actually drop support of java.sql types from core databind in 3.0 -- a separate datatype module could be added for those who really want support for types. The benefit here would be removal of the whole of java.sql dependency form JPMS requirements (for Java 11 and beyond).

Will create a separate issue for that.

@michael-o
Copy link

I do support the separate module!

@cowtowncoder cowtowncoder added this to the 3.0.0 milestone Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.x Issues to be only tackled for Jackson 3.x, not 2.x
Projects
None yet
Development

No branches or pull requests

2 participants