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

Explicitly fail (de)serialization of java.time.* types in absence of registered custom (de)serializers #2683

Closed
cowtowncoder opened this issue Apr 8, 2020 · 3 comments
Milestone

Comments

@cowtowncoder
Copy link
Member

(inspired by #2626)

So, a relatively common problem by users seem to be the case of using Java 8 date/time types, without registered Java 8 date/time module. For serialization this can even produce seemingly legit JSON output as values are considered just POJOs/Beans, which is problematic as JSON representation will NOT be what module would support, nor something that can be deserialized.

While general case of knowing that something is missing wrt support is unsolvable, the specific case of java.time type support may be something we could perhaps detect.
My first idea is that when looking for (de)serializer, if no (de)serializer found via module registrations, trying to find one for java.time.* classes should give specific failure suggesting that module is needed, and NOT try to create Bean[De]Serializer.

Due to timing concerns (2.11.0.rc1 being tested, official 2.11.0 due soon) this will probably need to go in 2.12.0.

@cowtowncoder cowtowncoder added this to the 2.12.0 milestone May 5, 2020
@cowtowncoder
Copy link
Member Author

Implementing; appears to work, does not conflict with Java 8 date/time module when registered.

About the only open question is this: initial implementation will throw deferred exception -- that is, only when actual attempt is made to read/write values. But should it be eager failure instead, at least for deserialization? (serialization might be trickier).

@rajpra8
Copy link

rajpra8 commented Jan 26, 2021

If java 8 going to be minimum supported version at some point, can JavaTimeModule gets registered by default?

@cowtowncoder
Copy link
Member Author

Java 8 will be default for 2.13 (and was always at least Java 8 for Jackson 3.0).

However, I am still not 100% sure about direct inclusion due to sheer size of Java 8 date/time module.
Jackson 3.0 does embed other java 8 types (optionals) and parameter name introspection; 2.13 will likely include these too.

raboof added a commit to raboof/akka that referenced this issue Sep 9, 2021
Starting with FasterXML/jackson-databind#2683
Jackson will no longer use the generic bean serialization when serializing a
`java.time.Instant`, but throw an error (since the bean serialization
doesn't make sense for those types anyway).

Our test relied on the bean serialization to test using custom object
mappers. This PR improves the test to use a 'real' custom mapper instead
of just relying on the bean fallback.
raboof added a commit to akka/akka that referenced this issue Sep 10, 2021
Starting with FasterXML/jackson-databind#2683
Jackson will no longer use the generic bean serialization when serializing a
`java.time.Instant`, but throw an error (since the bean serialization
doesn't make sense for those types anyway).

Our test relied on the bean serialization to test using custom object
mappers. This PR improves the test to use a 'real' custom mapper instead
of just relying on the bean fallback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants