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

DateTimeSerializer does not respect SerializationFeature WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS #54

Open
zkiss opened this issue Jan 12, 2015 · 6 comments
Labels

Comments

@zkiss
Copy link

zkiss commented Jan 12, 2015

Serialization feature WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS is enabled by default in Jackson. Joda does not have nano precision. The solution to this should be an optional multiplication by 1000 when necessary when serializing (and deserializing) as well.

@cowtowncoder
Copy link
Member

This is a rather tricky one -- I agree in principle here, but the implications for backwards compatibility can be tricky. So it would be worth discussing on Jackson dev list. If consensus is that we should just go ahead, I'd be happy to change it or merge a patch that does this.

@zkiss
Copy link
Author

zkiss commented Jan 13, 2015

Actually, the solution is not that simple (multiplication by 1000), firstly, because the multiplication is by 1000000 (oops :)) and secondly this could cause the value to be too big for a long to handle. Probably the simplest solution would be just adding 6 zeros at the end, if possible, or using a BigDecimal to do the calculation. I'm not subscribed to the dev list, but I guess I'm not essential for this discussion.

@zkiss
Copy link
Author

zkiss commented Jan 26, 2015

@cowtowncoder Is there a suggested way to go here? Happy to create a PR for this, but for that I'd like to know what your concerns are?

@zkiss
Copy link
Author

zkiss commented Feb 21, 2015

I have just noticed that the javadocs specifically say that only those modules should respect these serialization settings if the data type they serialize has nano resolution.

This however leaves no room for making the joda module work with jsr310 in case jsr310 serializes in nanos.

Either the API contract could be changed which would break backwards compatibility or a new switch could be introduced for the modules which do not support nano precision (would be awkward).

I was also thinking if it was possible - or desirable - to introduce module-level serialization/deserialization features which would only specify api contracts on the behaviour of the module itself. That would allow a less generic configuration of modules which probably would be easier to understand in cases which are specific to modules.

@cowtowncoder
Copy link
Member

FWIW, I think it is completely reasonable to have module-level configuration.

However, there is one practical challenge: whereas global SerializationFeature/DeserializationFeature may be changed on per-call basis (via ObjectReader / ObjectWriter), there is currently no mechanism to cleanly do that for modules: modules have no connection to mapper/reader/writer after registration.

@cowtowncoder
Copy link
Member

I am not sure how to proceed with this one; it probably has to be part of bigger concentrated overhaul for 3.x; maybe to allow 4 alternative timestamp base units: seconds, milliseconds, microseconds, nanoseconds (or whatever is set of commonly used ones).

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

No branches or pull requests

2 participants