-
Notifications
You must be signed in to change notification settings - Fork 562
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
Support i128 and u128 #846
Comments
To expand a little, I'm using I'll first try to find a workaround and share it, but it would be lovely to know why serializing |
After a bit of a wild goose chase. serde_json is happy to serialize to This also means that my issue, in the end, was converting |
I think |
RE: or don't use I would still be interested to hear @dtolnay , perhaps also helpful to link people to in the future, why not support the larger numbers? It seems JSON has no opinion on how large numbers can be, why does serde_json? Thanks for the quick reply! |
JSON doesn't not have an opinion, JSON has the opinion that implementations define the limit on their range and precision of numbers.
If anything, it appears to consider
https://www.rfc-editor.org/rfc/rfc8259 You are commenting as though JSON has the opinion that implementations ought to support arbitrarily big numbers, which is not reflected in the text. On the Rust side of things, I think those people expecting to put u128 inside |
Reading the section on numbers I'd agree with you! Accepting
Ah, I didn't mean to imply as much. Only that one may when the implementation supports it, reading the full section I'd say ought or should is be double precision float compatible. Perhaps in a far-future scenario serde_json could default to f64 but allow the user to use pick any number the rust implementation supports. I'm not suggesting to implement such a thing now. Thanks for the rationalization, for others reading along I'd then update my conclusion to be: stay |
My two cents. The reason why people expect You are assuming that people know that values in JSON are implicitly (as per the fact that it is Java Script Object Notation), and immediately see that the built-in type So IMO, there were three possible architectures that could have been adopted which would have avoided this issue.
All of the above solutions make the user aware of the problem, in the situation where something like |
Currently by default this crate supports numbers up to 64-bits. For larger types it is necessary to enable the
arbitrary_precision
feature, which treats numbers as strings. Whilst this works, it can have unintended consequences as it changes the semantics of how integers are fed into the serde machinery - see #845.I wonder if serde_json might add support for 128-bit types within
Number
and the associated serializer implementations on platforms that support such types - e.g. by using serde_if_integer128. This would allow crates to use 128-bit types without needing to opt-in toarbitrary_precision
.I would be happy to contribute a PR if this is an acceptable course of action?
The text was updated successfully, but these errors were encountered: