Merge pull request #112 from ephraimkunz/same-child-name

Fix bug where nested structs with the same element names don't deserialize properly.
This commit is contained in:
Marc-Antoine ARNAUD
2021-05-30 19:28:58 +02:00
committed by GitHub
2 changed files with 17 additions and 11 deletions

View File

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

View File

@@ -373,6 +373,12 @@ pub fn parse(
); );
match event { match event {
::xml::reader::XmlEvent::StartElement{ref name, ref attributes, ..} => { ::xml::reader::XmlEvent::StartElement{ref name, ref attributes, ..} => {
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() { match name.local_name.as_str() {
#call_visitors #call_visitors
_ => { _ => {
@@ -386,6 +392,7 @@ pub fn parse(
} }
} }
} }
}
if depth == 0 { // Look for attributes only at element start if depth == 0 { // Look for attributes only at element start
#attributes_loading #attributes_loading
} }