-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
enhance ObjectTypeBinder to works with number type 'int' #989
Conversation
- number double or integer google#525 - integer values of array become a float values google#559
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
CLA signed (individual) |
CLAs look good, thanks! |
A few issues. Most importantly, check for integer overflow (NumberFormatException), and exponent notation ("e" in addition to "."). Maybe use Long instead of Integer? Now, even Long and Double may overflow, in the latter case losing precision. Also, doubles typically lose precision when converting from decimal, even if not overflowing. I think the best option would be to return BigDecimal instead of Double, and BigInteger instead of Integer. Opinions? |
When it will be merged to muster and released? |
@jobh
I can change the "integer" code to "long" one anytime, |
I believe not only me wait for this fix... |
@swankjesse Looks like a reasonable change to me. I plan to merge it in the next few days unless I hear a concern from you. |
Changing the type of a thing is extremely incompatible. If we merge this, nobody will be able to upgrade safely. |
assertEquals(5.0, map.get("a")); | ||
assertEquals(Arrays.asList(1.0, 2.0, null), map.get("b")); | ||
Map<?, ?> map = (Map<?, ?>) adapter.fromJson("{\"a\":5,\"b\":[1,2.0,null],\"c\":{\"x\":\"y\"}}"); | ||
assertEquals(5, map.get("a")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically, this is not at all backwards-compatible.
@swankjesse does it mean that in gson int will be never converted to correct type if it is not specified in end object directly? |
Though the label
Making |
@swankjesse but with current implementation if we deserialize json and serialize it back we will get different jsons. I believe it is not an expected behavior. |
This class looks like it was designed for the purpose - com.google.gson.internal.LazilyParsedNumber
|
@swankjesse @jobh |
the reason I pr this:
@RequestBody
parses integer params to double valuesint
should be parsedint
, notdouble
int
,so I hope this PR does not violate any rules.
related issues