xml
xml copied to clipboard
Does not pass unknown fields properly
For xml:
<a>
<b>
<c>5<c/>
<b/>
<other>
<d>6<d/>
<other/>
<a/>
with Rust structures:
#[derive(Deserialize, Debug)]
struct a {
other: Vec<other>,
}
#[derive(Deserialize, Debug)]
struct other {
d: i32,
}
serde_xml will fail with error at runtime (Expected text), and it is fixed by declaring an empty struct and adding a field of that type to a atructure a.
#[derive(Deserialize, Debug)]
struct Empty;
#[derive(Deserialize, Debug)]
struct a {
b: Empty,
other: Vec<other>,
}
#[derive(Deserialize, Debug)]
struct other {
d: i32,
}
Ah, it doesn't even work like that :(
Sounds reasonable to ignore unknown fields in xml. iirc json does the same
for now you can probably stick a xml::Value into the field and everything should work (although inefficiently)
@oli-obk thanks! Yes, it was a hugely requested feature for serde-json, afaik. Thanks for the suggested workaround!