Allow struct fields be named as 'name' (issue #21)
This commit is contained in:
@@ -350,3 +350,21 @@ fn de_attribute_enum() {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn de_name_issue_21() {
|
||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "book")]
|
||||
pub struct Book {
|
||||
name: String,
|
||||
}
|
||||
|
||||
let content = "<book><name>Little prince</name></book>";
|
||||
convert_and_validate!(
|
||||
content,
|
||||
Book,
|
||||
Book {
|
||||
name: String::from("Little prince"),
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -298,3 +298,19 @@ fn ser_attribute_enum() {
|
||||
let content = "<?xml version=\"1.0\" encoding=\"utf-8\"?><base color=\"pink\" />";
|
||||
convert_and_validate!(model, content);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ser_name_issue_21() {
|
||||
#[derive(YaSerialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "base")]
|
||||
pub struct XmlStruct {
|
||||
name: String,
|
||||
}
|
||||
|
||||
let model = XmlStruct {
|
||||
name: "something".to_string(),
|
||||
};
|
||||
|
||||
let content = "<?xml version=\"1.0\" encoding=\"utf-8\"?><base><name>something</name></base>";
|
||||
convert_and_validate!(model, content);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user