Fix bug where nested structs with the same element names didn't deserialzie properly.

This commit is contained in:
Ephraim Kunz 2021-05-05 07:34:38 -07:00
parent fb19a35d43
commit 72d61e03f4
2 changed files with 17 additions and 11 deletions

View File

@ -1052,6 +1052,5 @@ fn de_same_field_name_but_some_other_fields_or_something() {
};
serialize_and_validate!(model, content);
// TODO fix it
// deserialize_and_validate!(content, model, FooOuter);
deserialize_and_validate!(content, model, FooOuter);
}

View File

@ -367,16 +367,23 @@ pub fn parse(
);
match event {
::xml::reader::XmlEvent::StartElement{ref name, ref attributes, ..} => {
match name.local_name.as_str() {
#call_visitors
_ => {
let event = reader.next_event()?;
#write_unused
if depth == 0 && name.local_name == #root {
// Consume root element. We must do this first. In the case it shares a name with a child element, we don't
// want to prematurely match the child element below.
let event = reader.next_event()?;
#write_unused
} else {
match name.local_name.as_str() {
#call_visitors
_ => {
let event = reader.next_event()?;
#write_unused
if depth > 0 { // Don't skip root element
reader.skip_element(|event| {
#write_unused
})?;
if depth > 0 { // Don't skip root element
reader.skip_element(|event| {
#write_unused
})?;
}
}
}
}