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

Jdk8Module support for java8 Date classes serialization #35

Closed
pragmaticway opened this issue Jul 28, 2017 · 4 comments
Closed

Jdk8Module support for java8 Date classes serialization #35

pragmaticway opened this issue Jul 28, 2017 · 4 comments

Comments

@pragmaticway
Copy link

I'm moving from JSR310Module to Jdk8Module and have noticed that Jdk8Module is not supporting java8 Date classes (LocalDateTime, etc.)

So my old JSR310 code that is producing correct date/time format is:

mapper.registerModule(new JSR310Module());
mapper.setDateFormat(new ISO8601DateFormat());

so it generates "2017-07-28T12:32:39.927"

But when I move to Jdk8Module:

mapper.registerModule(new Jdk8Module());
mapper.setDateFormat(new ISO8601DateFormat());

it generates "{"year":2017,"month":"JULY","dayOfYear":209,"dayOfWeek":"FRIDAY","dayOfMonth":28,"monthValue":7,"hour":12,"minute":45,"second":53,"nano":458000000,"chronology":{"id":"ISO","calendarType":"iso8601"}}"

After looking around in the docs looks like Jdk8Module isn't supporting Java8 new date classes. Instead I have to use JSR310's JavaTime module for that:

mapper.registerModule(new Jdk8Module());
mapper.registerModule(new com.fasterxml.jackson.datatype.jsr310.JavaTimeModule());
mapper.setDateFormat(new ISO8601DateFormat());

so it generates "2017-07-28T12:32:39.927"

Can you please implement support for java8 new Date classes in Jdk8Module (not in some other module)?

Thank you in advance!

@cowtowncoder
Copy link
Member

I think you may have misunderstood what modules in question provide; Jdk8Module is NOT a replacement for JSR310Module -- instead, JavaTimeModule is.

While name Jdk8Module is bit misleading, it comes from Maven package jackson-datatype-jdk8 which is just part of support for Java 8:

  • jackson-module-parameter-names adds support for accessing method/constructor parameter names that Java 8 bytecode has
  • jackson-datatype-jsr310 module has support for Java 8 date/time datatypes
  • jackson-datatype-jdk8 modules has support for other additions: most importantly optionals.

This division of modules has been in place during Jackson 2.x and can not be simply changed without other complications. But with Jackson 3.x baseline for JDK will be increased so that module structure will probably be changed -- most likely so that "optionals" and parameter-names support will be in-built, and date/time types remain as an add-on (due to size of module; other 2 aspects are relatively small).

@pragmaticway
Copy link
Author

pragmaticway commented Jul 28, 2017

But jackson-datatype-jsr310 stated as DEPRECATED.

It says:
(DEPRECATED) -- moved under jackson-modules-java8

See https://github.com/FasterXML/jackson-datatype-jsr310

@cowtowncoder
Copy link
Member

@pragmaticway Yes: the git repository itself is deprecated, and module within has moved under jackson-moduleS-java8, which is a multi-maven-module repository. Did you look at that repository to try to understand how things work?

I can understand that this might be confusing, but I would hope users take some time to try to solve the problem, and where applicable, suggest improvements to descriptions. I will try to improve the wording to reduce confusion.

@pragmaticway
Copy link
Author

@cowtowncoder Thank you for clarifying!

Yes indeed the documentation about deprecated module is somewhat ambiguous and confusing. Myself and my teammates were under impression that we supposed to use Jdk8Module instead of deprecated JSR310Module - but in fact it turned out its not, instead we should use another module dedicated to java8 new Date classes which for some reason located in "deprecated" package jsr310, e.g.: com.fasterxml.jackson.datatype.jsr310.JavaTimeModule

That was adding to the confusion. Now since its clarified that jsr310 module is not deprecated, it makes more sense.
I think it will be a benefit to the community if the documentation cleared up regarding this "JSR310 deprecated statement"

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