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(
|
pub fn parse(
|
||||||
data_struct: &DataStruct,
|
data_struct: &DataStruct,
|
||||||
name: &Ident,
|
name: &Ident,
|
||||||
|
root_namespace: &str,
|
||||||
root: &str,
|
root: &str,
|
||||||
root_attributes: &YaSerdeAttribute,
|
root_attributes: &YaSerdeAttribute,
|
||||||
generics: &Generics,
|
generics: &Generics,
|
||||||
@ -419,13 +420,13 @@ pub fn parse(
|
|||||||
);
|
);
|
||||||
match event {
|
match event {
|
||||||
::yaserde::__xml::reader::XmlEvent::StartElement{ref name, ref attributes, ..} => {
|
::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
|
// 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.
|
// want to prematurely match the child element below.
|
||||||
let event = reader.next_event()?;
|
let event = reader.next_event()?;
|
||||||
#write_unused
|
#write_unused
|
||||||
} else {
|
} else {
|
||||||
let namespace = name.namespace.clone().unwrap_or_default();
|
|
||||||
|
|
||||||
match (namespace.as_str(), name.local_name.as_str()) {
|
match (namespace.as_str(), name.local_name.as_str()) {
|
||||||
#call_visitors
|
#call_visitors
|
||||||
|
|||||||
@ -14,16 +14,28 @@ pub fn expand_derive_deserialize(ast: &syn::DeriveInput) -> Result<TokenStream,
|
|||||||
|
|
||||||
let root_attributes = YaSerdeAttribute::parse(attrs);
|
let root_attributes = YaSerdeAttribute::parse(attrs);
|
||||||
|
|
||||||
let root_name = format!(
|
let root_name = root_attributes.xml_element_name(name);
|
||||||
"{}{}",
|
let root_namespace = root_attributes
|
||||||
root_attributes.prefix_namespace(),
|
.namespaces
|
||||||
root_attributes.xml_element_name(name)
|
.iter()
|
||||||
);
|
.find_map(|(prefix, namespace)| {
|
||||||
|
if root_attributes.prefix.eq(prefix) {
|
||||||
|
Some(namespace.clone())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
let impl_block = match *data {
|
let impl_block = match *data {
|
||||||
syn::Data::Struct(ref data_struct) => {
|
syn::Data::Struct(ref data_struct) => expand_struct::parse(
|
||||||
expand_struct::parse(data_struct, name, &root_name, &root_attributes, generics)
|
data_struct,
|
||||||
}
|
name,
|
||||||
|
&root_namespace,
|
||||||
|
&root_name,
|
||||||
|
&root_attributes,
|
||||||
|
generics,
|
||||||
|
),
|
||||||
syn::Data::Enum(ref data_enum) => {
|
syn::Data::Enum(ref data_enum) => {
|
||||||
expand_enum::parse(data_enum, name, &root_name, &root_attributes, generics)
|
expand_enum::parse(data_enum, name, &root_name, &root_attributes, generics)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user