fix: fix nesting struct parsing bug
issue #192 Signed-off-by: limingyi <lessu@163.com>
This commit is contained in:
parent
e783c29c47
commit
890fdb5629
@ -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,
|
||||
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user