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

Allow LocalDate to be serialized/deserialized as number (epoch day) #20

Closed
kewne opened this issue Mar 15, 2017 · 6 comments
Closed

Allow LocalDate to be serialized/deserialized as number (epoch day) #20

kewne opened this issue Mar 15, 2017 · 6 comments
Milestone

Comments

@kewne
Copy link

kewne commented Mar 15, 2017

The LocalDateSerializer only supports serializing LocalDate instances as strings or arrays, both of which suffer from localization issues ("is it year-month-day or year-day-month?").

An alternative would be to use LocalDate#toEpochDay() and LocalDate#ofEpochDay(long), thus allowing a (less human readable but) unambiguous format.

@cowtowncoder
Copy link
Member

cowtowncoder commented Mar 15, 2017

If there is indeed variant to convert to/from long, supporting @JsonFormat(shape=Shape.NUMBER) would make sense I think? Support should also require deserializer handling.

@kewne
Copy link
Author

kewne commented Mar 16, 2017

Yep, both serialization and deserialization should be supported, and using shape=Shape.Number too.

I've forked the repo to try to work on this myself but the build fails with missing poms, is there a specific layout that's needed for building?

@kevinjom
Copy link
Contributor

@kewne in my experience, clone the jackson-bom repo, run mvn clean install and then go back to this repo, run whatever you want.

@kewne
Copy link
Author

kewne commented Mar 24, 2017

@kevinjom Got it working, thanks!

@cowtowncoder I'm looking through the code but I'm having difficulty understanding the rationale behind some of the formatting: some zeroes are added to the fractional part of the result "to avoid interpretation as integral number".
I've also found FasterXML/jackson-datatype-jsr310#67 which references something similar, what's the desired format?

kewne pushed a commit to kewne/jackson-modules-java8 that referenced this issue Mar 24, 2017
@cowtowncoder
Copy link
Member

@kewne excellent! I did not write this module originally, so some of the logic predates my changes. I don't recall part about additional zeroes, which should not be necessary to just differentiate between JSON integers vs floating-point numbers.

@cowtowncoder
Copy link
Member

As per notes on PR, will merge as soon as we get CLA; will make it in 2.9(.0.pr3)

cowtowncoder added a commit that referenced this issue Mar 27, 2017
#20 Allow `LocalDate` to be serialized/deserialized as number (epoch day)
cowtowncoder added a commit that referenced this issue Mar 27, 2017
@cowtowncoder cowtowncoder added this to the 2.9.0.pr3 milestone Mar 27, 2017
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

3 participants