tafia / quick-xml

Rust high performance xml reader and writer
MIT License
1.22k stars 237 forks source link

How to deserialize Decimal? #787

Closed Zzaniu closed 4 months ago

Zzaniu commented 4 months ago
#[test]
fn test_decimal() {
    #[derive(Debug, serde::Deserialize)]
    struct A {
        a: rust_decimal::Decimal,
    }

    let s = r#"<root><a>100.2</a></root>"#;
    let x = quick_xml::de::from_str::<A>(s).unwrap();
    println!("{:#?}", x);
}

called `Result::unwrap()` on an `Err` value: Custom("invalid type: map, expected a Decimal type representing a fixed-point number")
Mingun commented 4 months ago

According to the documentation of rust_decimal, I think, you should enable serde-str feature of that crate