-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
Hi, thank you for writing the JSON5 serializer/deserializer. During my tests I found that an object like { 0: "hello" } returns error, I leave you a test case here:
#[test]
fn json5test() {
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Duck {
name: String,
age: usize,
}
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct DuckFamily {
triplets: BTreeMap<usize, Duck>,
}
let family = {
let mut triplets = BTreeMap::new();
triplets.insert(
1,
Duck {
name: "Huey".to_owned(),
age: 9,
},
);
triplets.insert(
2,
Duck {
name: "Dewey".to_owned(),
age: 9,
},
);
triplets.insert(
3,
Duck {
name: "Louie".to_owned(),
age: 9,
},
);
DuckFamily { triplets }
};
let encoded = json5::to_string(&family).unwrap();
println!("{:?}", &encoded);
let decoded: DuckFamily = json5::from_str(&encoded).unwrap(); // error here
println!("{:?}", &decoded);
assert_eq!(decoded, family);
}Metadata
Metadata
Assignees
Labels
No labels