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

Double / Long deserialize #1679

Closed
yuvalp-k2view opened this issue Apr 13, 2020 · 4 comments
Closed

Double / Long deserialize #1679

yuvalp-k2view opened this issue Apr 13, 2020 · 4 comments

Comments

@yuvalp-k2view
Copy link

Sometimes it is useful to parse '5' as long vs '5.0' as double, especially when parsing arbitrary data.

This would make the serialize/deserialize of numbers symetric (5.0 > "5.0" > 5.0, 5L > "5" > 5L)

I'd like to suggest a new builder param:
setNumberDererializationPolicy()
default will remain as is
however, user will be able to specify:
setNumberDererializationPolicy(NumberDererializationPolicy.LONG_SUPPORT)

I think this presents a good compromise between the spec being strictly double and the reality where double has precision issues and users need a way to store longs in arbitrary json.

We'd be happy to create a PR if this is acceptable

@lyubomyr-shaydariv
Copy link
Contributor

Possible duplicate of #1290 :

Gson gson = new GsonBuilder()
  .setNumberToNumberStrategy(ToNumberPolicy.LONG_OR_DOUBLE)
  .create();

@yuvalp-k2view
Copy link
Author

I agree... but I see this PR is waiting for a long time. Do you know if there is anything wrong with it? If there are fixes needed we'd be happy to contribute.

@lyubomyr-shaydariv
Copy link
Contributor

@yuvalp-k2view

Do you know if there is anything wrong with it?

No idea, there was no review from the project members.

@eamonnmcmanus
Copy link
Member

Fixed by #1290.

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