Fixed the struct map interaction with serial_name. Added a separarte JSON test for serial_name.

This commit is contained in:
kvark
2014-09-07 10:43:15 -04:00
parent 4a713cdbea
commit 2224e9afdf
3 changed files with 55 additions and 12 deletions
+31
View File
@@ -0,0 +1,31 @@
#![feature(phase)]
extern crate serde;
#[phase(plugin)]
extern crate serde_macros;
#[deriving(PartialEq, Show)]
#[deriving_serializable]
#[deriving_deserializable]
struct Test {
#[serial_name = "$schema"]
schema: String,
title: String,
#[serial_name = "type"]
ty: int
}
#[test]
fn test_json_struct() {
let input = Test {
schema: "a".to_string(),
title: "b".to_string(),
ty: 3,
};
let s = serde::json::to_string(&input).unwrap();
assert_eq!(s.as_slice(), r#"{"$schema":"a","title":"b","type":3}"#);
let output: Test = serde::json::from_str(s.as_slice()).unwrap();
assert_eq!(input, output);
}