mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-22 19:28:01 +00:00
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:
@@ -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"),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user