Added support for newtype variant serialization
This commit is contained in:
parent
ebc61baab2
commit
f1af2dc5ab
@ -1164,12 +1164,12 @@ impl<'a, M> Serializer for FlatMapSerializer<'a, M>
|
||||
_: &'static str,
|
||||
_: u32,
|
||||
_: &'static str,
|
||||
_: &T,
|
||||
value: &T,
|
||||
) -> Result<Self::Ok, Self::Error>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
Err(self.bad_type(Unsupported::Enum))
|
||||
value.serialize(self)
|
||||
}
|
||||
|
||||
fn serialize_seq(self, _: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> {
|
||||
|
@ -140,6 +140,12 @@ enum FlattenStructTagContentEnum {
|
||||
index: u32,
|
||||
value: u32
|
||||
},
|
||||
NewtypeVariant(FlattenStructTagContentEnumNewtypeVariant),
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
struct FlattenStructTagContentEnumNewtypeVariant {
|
||||
value: u32,
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1441,3 +1447,49 @@ fn test_flatten_struct_tag_content_enum() {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_flatten_struct_tag_content_enum_newtype() {
|
||||
let change_request = FlattenStructTagContentEnumWrapper {
|
||||
outer: 42,
|
||||
data: FlattenStructTagContentEnumNewtype(
|
||||
FlattenStructTagContentEnum::NewtypeVariant(
|
||||
FlattenStructTagContentEnumNewtypeVariant {
|
||||
value: 23
|
||||
}
|
||||
)
|
||||
),
|
||||
};
|
||||
assert_de_tokens(
|
||||
&change_request,
|
||||
&[
|
||||
Token::Map { len: None },
|
||||
Token::Str("outer"),
|
||||
Token::U32(42),
|
||||
Token::Str("type"),
|
||||
Token::Str("newtype_variant"),
|
||||
Token::Str("value"),
|
||||
Token::Map { len: None },
|
||||
Token::Str("value"),
|
||||
Token::U32(23),
|
||||
Token::MapEnd,
|
||||
Token::MapEnd,
|
||||
],
|
||||
);
|
||||
assert_ser_tokens(
|
||||
&change_request,
|
||||
&[
|
||||
Token::Map { len: None },
|
||||
Token::Str("outer"),
|
||||
Token::U32(42),
|
||||
Token::Str("type"),
|
||||
Token::Str("newtype_variant"),
|
||||
Token::Str("value"),
|
||||
Token::Struct { len: 1, name: "FlattenStructTagContentEnumNewtypeVariant" },
|
||||
Token::Str("value"),
|
||||
Token::U32(23),
|
||||
Token::StructEnd,
|
||||
Token::MapEnd,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user