Fix number deserialization with arbitrary_precision#586
Conversation
When we have a struct that uses `#[serde(flatten)]` and the feature `arbitrary_precision` is enabled, the deserialization. The problem was that the arbitrary number was forwarded as a "map" to the visitor and in a later step this map failed as a number was expected. Fixes: serde-rs#505
9d01c09 to
ab8c208
Compare
| ("1.0\t", "invalid number at line 1 column 4"), | ||
| ]); | ||
|
|
||
| #[cfg(feature = "arbitrary_precision")] |
There was a problem hiding this comment.
I removed this test + the extra added function from_string_unchecked. In my opinion this test does not makes that much sense at all. Even if we would have parsed the 1e999 correctly into the Number, there is not way to get this value out of the object.
|
The patch seems still failing the test, which would have been passed without "arbitrary_precision" feature. use serde::{Deserialize};
#[derive(Deserialize)]
#[serde(tag = "tag")]
#[derive(Clone, Debug, PartialEq)]
pub enum E1 {
A{v: f64},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn serde_1() {
let incoming_str = r#"{"tag":"A","v":0}"#;
let expected_incoming = E1::A{ v: 0.0 };
let incoming = serde_json::from_str(&incoming_str).expect("cannot deserialize incoming_str");
assert_eq!(expected_incoming, incoming);
}
}
|
dtolnay
left a comment
There was a problem hiding this comment.
Hi @bkchr, thanks for the PR but I can't accept this because it breaks the following:
// [dependencies]
// serde_json = { version = "1.0", features = ["arbitrary_precision"] }
fn main() {
println!("{}", serde_json::from_str::<serde_json::Value>("1e999").unwrap());
}This is what is tested by the test you removed. The point of arbitrary_precision is to allow deserializing and round-tripping arbitrarily large numbers without losing precision.
When we have a struct that uses
#[serde(flatten)]and the featurearbitrary_precisionis enabled, the deserialization. The problem wasthat the arbitrary number was forwarded as a "map" to the visitor and in
a later step this map failed as a number was expected.
Fixes: #505
Requires: serde-rs/serde#1679