serde-rs / json

Strongly typed JSON library for Rust
Apache License 2.0
4.7k stars 536 forks source link

`arbitrary_precision` breaks float deserialisation in untagged enum #1108

Open LDeakin opened 5 months ago

LDeakin commented 5 months ago

Without arbitrary_precision the following runs without error:

#[derive(Debug, PartialEq, serde::Deserialize)]
#[serde(untagged)]
pub enum Num {
    Float(f64),
}

fn main() {
    assert_eq!(serde_json::from_str::<Num>(r#"1.0"#).unwrap(), Num::Float(1f64));
}

With arbitrary_precision, serde_json::from_str::<Num>(r#"1.0"#) fails with Error("data did not match any variant of untagged enum Num", line: 0, column: 0).

This issue is similar.