Reject serializing maps to JSON with non-string keys

Closes #122. This is a breaking change since it modifies the
return type of serde_json::to_vec{,pretty}, so it'll require a major
version bump of serde_json.
This commit is contained in:
Erick Tryzelaar
2015-08-13 22:29:13 -07:00
parent fc58ea7487
commit fe20852b2c
4 changed files with 205 additions and 125 deletions
+13
View File
@@ -1348,3 +1348,16 @@ fn test_deserialize_from_stream() {
assert_eq!(request, response);
}
#[test]
fn test_serialize_rejects_non_key_maps() {
let map = treemap!(
1 => 2,
3 => 4
);
match serde_json::to_vec(&map).unwrap_err() {
serde_json::Error::SyntaxError(serde_json::ErrorCode::KeyMustBeAString, 0, 0) => {}
_ => panic!("integers used as keys"),
}
}