json: Parser cannot read arbitrary precision numbers
http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf specifies in the second paragraph of the introduction that JSON is agnostic about numbers, and simply represents them as a series of digits.
However, serde-json parses anything with a decimal point as a Rust f64
, which causes numbers to be read incorrectly. There is no way to avoid this because this behaviour is chosen as soon as a decimal point is encountered. This makes it impossible to use serde-json to interoperate with financial software using JSON.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 1
- Comments: 21 (16 by maintainers)
#348 has a promising implementation with the same API as #252 but without relying on unstable specialization. It also interacts better with deserializer “adapters” like
erased-serde
,serde-ignored
, andserde-encrypted-value
which would not have worked with specialization.Sure, here’s a simple test with the current versions:
For hjson I adopted your code to do the testing but then fed the string to
str.parse::<f64>()
.@nubis Okay but once you parse it, what do you do with the result? The Visitor trait will require you to convert it to f64 in order to do anything.
You are going to need to fix https://github.com/serde-rs/serde/issues/185 before you fix this.