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

Internally tagged enums are confused #26

Open vorner opened 7 years ago

vorner commented 7 years ago

It seems when using the internally tagged enums, the deserializer gets somewhat confused. If I have this code:

#[derive(Deserialize)]
#[serde(tag = "z")]
enum Z {
    A { b: String },
    B { c: String },
}
#[derive(Deserialize)]
struct X {
    y: Z,
}
let x = br#"<x><y z="A"><b>hello</b></y></x>"#;
serde_xml_rs::deserialize::<_, X>(Cursor::new(x)).unwrap();

it produces this error:

invalid type: map, expected a string

I believe this should actually work. This code does work:

#[derive(Deserialize)]
struct Z {
    z: String,
    b: String,
}
#[derive(Deserialize)]
struct X {
    y: Z,
}
let x = br#"<x><y z="A"><b>hello</b></y></x>"#;
serde_xml_rs::deserialize::<_, X>(Cursor::new(x)).unwrap();

I know the internally-tagged thing is a bit weird in XML, but I actually discovered it in real-life (parsing the conntrack XML output).

farodin91 commented 7 years ago

Any idea how to fix it? @oli-obk

oli-obk commented 7 years ago

Not really. Maybe a trace gives some insights?