From b3d9ea074420891bcffaf42fb26d66c8f8742466 Mon Sep 17 00:00:00 2001 From: Dmitry Samoylov Date: Tue, 24 Mar 2020 17:39:16 +0700 Subject: [PATCH] Fix issue 12 for attributes --- yaserde/tests/deserializer.rs | 33 ++++++++++++++++++++++++++ yaserde_derive/src/de/expand_struct.rs | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/yaserde/tests/deserializer.rs b/yaserde/tests/deserializer.rs index 42463d9..0035fe7 100644 --- a/yaserde/tests/deserializer.rs +++ b/yaserde/tests/deserializer.rs @@ -854,3 +854,36 @@ fn de_subitem_issue_12_attributes() { Struct { id: 54 } ); } + +#[test] +fn de_subitem_issue_12_attributes_with_sub() { + #[derive(Default, PartialEq, Debug, YaDeserialize)] + pub struct SubStruct { + #[yaserde(attribute)] + id: i32, + } + + #[derive(Default, PartialEq, Debug, YaDeserialize)] + pub struct Struct { + #[yaserde(attribute)] + id: i32, + sub1: SubStruct, + sub2: SubStruct, + } + + convert_and_validate!( + r#" + + + + + + "#, + Struct, + Struct { + id: 54, + sub1: SubStruct { id: 63 }, + sub2: SubStruct { id: 72 } + } + ); +} diff --git a/yaserde_derive/src/de/expand_struct.rs b/yaserde_derive/src/de/expand_struct.rs index d22652a..e76770b 100644 --- a/yaserde_derive/src/de/expand_struct.rs +++ b/yaserde_derive/src/de/expand_struct.rs @@ -423,7 +423,7 @@ pub fn parse( // return Err(format!("unknown key {}", name)) // } } - if !skipped { + if depth == 0 && !skipped { // Look for attributes only at element start #attributes_loading } depth += 1;