Allow integer key in untagged flattened map

This commit is contained in:
David Tolnay 2019-06-23 12:05:02 -07:00
parent dbd67c6c89
commit afb1754528
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 30 additions and 0 deletions

View File

@ -1420,6 +1420,7 @@ mod content {
Content::ByteBuf(v) => visitor.visit_byte_buf(v),
Content::Bytes(v) => visitor.visit_borrowed_bytes(v),
Content::U8(v) => visitor.visit_u8(v),
Content::U64(v) => visitor.visit_u64(v),
_ => Err(self.invalid_type(&visitor)),
}
}
@ -2123,6 +2124,7 @@ mod content {
Content::ByteBuf(ref v) => visitor.visit_bytes(v),
Content::Bytes(v) => visitor.visit_borrowed_bytes(v),
Content::U8(v) => visitor.visit_u8(v),
Content::U64(v) => visitor.visit_u64(v),
_ => Err(self.invalid_type(&visitor)),
}
}

View File

@ -1466,6 +1466,34 @@ fn test_internally_tagged_struct_with_flattened_field() {
);
}
#[test]
fn test_untagged_enum_with_flattened_integer_key() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Untagged {
Variant {
#[serde(flatten)]
map: BTreeMap<u64, String>,
},
}
assert_tokens(
&Untagged::Variant {
map: {
let mut map = BTreeMap::new();
map.insert(100, "BTreeMap".to_owned());
map
},
},
&[
Token::Map { len: None },
Token::U64(100),
Token::Str("BTreeMap"),
Token::MapEnd,
],
);
}
#[test]
fn test_enum_in_untagged_enum() {
#[derive(Debug, PartialEq, Serialize, Deserialize)]