diff --git a/yaserde/tests/deserializer.rs b/yaserde/tests/deserializer.rs
index 43ca8f8..b98462d 100644
--- a/yaserde/tests/deserializer.rs
+++ b/yaserde/tests/deserializer.rs
@@ -54,6 +54,27 @@ fn de_basic() {
);
}
+#[test]
+fn de_keyword() {
+ init();
+
+ #[derive(YaDeserialize, PartialEq, Debug)]
+ #[yaserde(root = "book")]
+ pub struct Book {
+ #[yaserde(attribute, rename = "ref")]
+ pub r#ref: String,
+ }
+
+ let content = "";
+ convert_and_validate!(
+ content,
+ Book,
+ Book {
+ r#ref: "978-1522968122".to_string()
+ }
+ );
+}
+
#[test]
fn de_dash_param() {
init();
diff --git a/yaserde/tests/serializer.rs b/yaserde/tests/serializer.rs
index ab615ef..754e0d4 100644
--- a/yaserde/tests/serializer.rs
+++ b/yaserde/tests/serializer.rs
@@ -326,6 +326,23 @@ fn ser_text_content_with_attributes() {
serialize_and_validate!(model, content);
}
+#[test]
+fn ser_keyword() {
+ #[derive(YaSerialize, PartialEq, Debug)]
+ #[yaserde(rename = "base")]
+ pub struct XmlStruct {
+ #[yaserde(attribute, rename = "ref")]
+ r#ref: String,
+ }
+
+ let model = XmlStruct {
+ r#ref: "978-1522968122".to_string(),
+ };
+
+ let content = "";
+ serialize_and_validate!(model, content);
+}
+
#[test]
fn ser_name_issue_21() {
#[derive(YaSerialize, PartialEq, Debug)]
diff --git a/yaserde_derive/src/common/field.rs b/yaserde_derive/src/common/field.rs
index 0d1884a..bc28e98 100644
--- a/yaserde_derive/src/common/field.rs
+++ b/yaserde_derive/src/common/field.rs
@@ -3,6 +3,7 @@ use heck::CamelCase;
use proc_macro2::Span;
use proc_macro2::{Ident, TokenStream};
use std::fmt;
+use syn::ext::IdentExt;
use syn::spanned::Spanned;
use syn::Type::Path;
@@ -43,7 +44,7 @@ impl YaSerdeField {
.syn_field
.ident
.clone()
- .map(|ident| syn::Ident::new(&format!("__{}_value", ident.to_string()), ident.span()))
+ .map(|ident| syn::Ident::new(&format!("__{}_value", ident.unraw()), ident.span()))
}
pub fn renamed_label_without_namespace(&self) -> String {