Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Does not pass unknown fields properly #19

Open
White-Oak opened this issue Jul 13, 2016 · 4 comments
Open

Does not pass unknown fields properly #19

White-Oak opened this issue Jul 13, 2016 · 4 comments

Comments

@White-Oak
Copy link

White-Oak commented Jul 13, 2016

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
Copy link
Author

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

@oli-obk
Copy link

oli-obk commented Jul 14, 2016

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

@oli-obk
Copy link

oli-obk commented Jul 14, 2016

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

@White-Oak
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants