Skip to content

Commit

Permalink
Merge branch 'lessu-nesting'
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcAntoine-Arnaud committed Sep 16, 2024
2 parents e783c29 + 890fdb5 commit 8c7926f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
5 changes: 3 additions & 2 deletions yaserde_derive/src/de/expand_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use syn::{DataStruct, Generics, Ident};
pub fn parse(
data_struct: &DataStruct,
name: &Ident,
root_namespace: &str,
root: &str,
root_attributes: &YaSerdeAttribute,
generics: &Generics,
Expand Down Expand Up @@ -419,13 +420,13 @@ pub fn parse(
);
match event {
::yaserde::__xml::reader::XmlEvent::StartElement{ref name, ref attributes, ..} => {
if depth == 0 && name.local_name == #root {
let namespace = name.namespace.clone().unwrap_or_default();
if depth == 0 && name.local_name == #root && namespace.as_str() == #root_namespace {
// 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 {
let namespace = name.namespace.clone().unwrap_or_default();

match (namespace.as_str(), name.local_name.as_str()) {
#call_visitors
Expand Down
28 changes: 20 additions & 8 deletions yaserde_derive/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,28 @@ pub fn expand_derive_deserialize(ast: &syn::DeriveInput) -> Result<TokenStream,

let root_attributes = YaSerdeAttribute::parse(attrs);

let root_name = format!(
"{}{}",
root_attributes.prefix_namespace(),
root_attributes.xml_element_name(name)
);
let root_name = root_attributes.xml_element_name(name);
let root_namespace = root_attributes
.namespaces
.iter()
.find_map(|(prefix, namespace)| {
if root_attributes.prefix.eq(prefix) {
Some(namespace.clone())
} else {
None
}
})
.unwrap_or_default();

let impl_block = match *data {
syn::Data::Struct(ref data_struct) => {
expand_struct::parse(data_struct, name, &root_name, &root_attributes, generics)
}
syn::Data::Struct(ref data_struct) => expand_struct::parse(
data_struct,
name,
&root_namespace,
&root_name,
&root_attributes,
generics,
),
syn::Data::Enum(ref data_enum) => {
expand_enum::parse(data_enum, name, &root_name, &root_attributes, generics)
}
Expand Down

0 comments on commit 8c7926f

Please sign in to comment.