xml icon indicating copy to clipboard operation
xml copied to clipboard

Does not pass unknown fields properly

Open White-Oak opened this issue 9 years ago • 4 comments

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,
}

White-Oak avatar Jul 13 '16 13:07 White-Oak

Ah, it doesn't even work like that :(

White-Oak avatar Jul 14 '16 15:07 White-Oak

Sounds reasonable to ignore unknown fields in xml. iirc json does the same

oli-obk avatar Jul 14 '16 16:07 oli-obk

for now you can probably stick a xml::Value into the field and everything should work (although inefficiently)

oli-obk avatar Jul 14 '16 16:07 oli-obk

@oli-obk thanks! Yes, it was a hugely requested feature for serde-json, afaik. Thanks for the suggested workaround!

White-Oak avatar Jul 14 '16 16:07 White-Oak