serde-xml-rs icon indicating copy to clipboard operation
serde-xml-rs copied to clipboard

Internally tagged enums are confused

Open vorner opened this issue 8 years ago • 2 comments

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).

vorner avatar Jul 17 '17 19:07 vorner

Any idea how to fix it? @oli-obk

farodin91 avatar Aug 23 '17 09:08 farodin91

Not really. Maybe a trace gives some insights?

oli-obk avatar Aug 23 '17 09:08 oli-obk