Adds serializer format specific field names

Allows different field names to be used for different external formats.

Field names are specified using the `rename` field attribute, e.g:

    #[serde(rename(xml= "a4", json="a5"))]

Reverts #62

Addresses #61
This commit is contained in:
Hugo Duncan
2015-04-27 18:05:54 -04:00
parent af752ddcb5
commit a935ebe8b9
10 changed files with 256 additions and 58 deletions
+4
View File
@@ -113,6 +113,10 @@ pub trait Deserializer {
{
self.visit(visitor)
}
fn fmt() -> &'static str {
""
}
}
///////////////////////////////////////////////////////////////////////////////
+5
View File
@@ -463,6 +463,11 @@ impl<Iter> de::Deserializer for Deserializer<Iter>
Err(self.error(ErrorCode::ExpectedSomeValue))
}
}
#[inline]
fn fmt() -> &'static str {
"json"
}
}
struct SeqVisitor<'a, Iter: 'a + Iterator<Item=io::Result<u8>>> {
+5
View File
@@ -256,6 +256,11 @@ impl<W, F> ser::Serializer for Serializer<W, F>
try!(self.formatter.colon(&mut self.writer));
value.serialize(self)
}
#[inline]
fn fmt() -> &'static str {
"json"
}
}
pub trait Formatter {
+10
View File
@@ -571,6 +571,11 @@ impl ser::Serializer for Serializer {
Ok(())
}
#[inline]
fn fmt() -> &'static str {
"value"
}
}
pub struct Deserializer {
@@ -677,6 +682,11 @@ impl de::Deserializer for Deserializer {
None => Ok(value)
}
}
#[inline]
fn fmt() -> &'static str {
"value"
}
}
struct SeqDeserializer<'a> {
+4
View File
@@ -179,6 +179,10 @@ pub trait Serializer {
fn visit_map_elt<K, V>(&mut self, key: K, value: V) -> Result<(), Self::Error>
where K: Serialize,
V: Serialize;
fn fmt() -> &'static str {
""
}
}
pub trait SeqVisitor {