RReverser / serde-xml-rs

xml-rs based deserializer for Serde (compatible with 1.0+)
https://crates.io/crates/serde-xml-rs
MIT License
270 stars 90 forks source link

Can't deserialize f32 #46

Closed kjeremy closed 7 years ago

kjeremy commented 7 years ago

In trying to deserialize:

#[derive(Debug, Deserialize)]
struct NoisePower {
    value: f32,
    units: String
}

#[derive(Debug, Deserialize)]
struct ReceiverReport {
    #[serde(rename = "NoisePower")]
    noise_power: NoisePower
}

#[test]
    fn receiver_noise_report_a() {
        let xml = r##"
            <!--<?xml version=”1.0” standalone=”yes”?>-->
            <ReceiverReport>
                <NoisePower value="-152.3" units="dBm"/>
            </ReceiverReport>
            "##;
        let report: ReceiverReport = deserialize(xml.as_bytes()).unwrap();
        println!("{:#?}", report);   
    }

I get:

'tests::receiver_noise_report_a' panicked at 'called Result::unwrap() on an Err value: invalid type: string "-152.3", expected f32', /checkout/src/libcore/result.rs:906:4

How do I ensure that NoisePower::value is deserialized as f32?

kjeremy commented 7 years ago

Duplicate of #25