Bug fix for #1449
Modified serialize_struct_as_struct. Added test test_internally_tagged_braced_struct_with_zero_fields
This commit is contained in:
parent
2359417804
commit
889e17816f
@ -333,7 +333,8 @@ fn serialize_struct_as_struct(
|
|||||||
.filter(|&field| !field.attrs.skip_serializing())
|
.filter(|&field| !field.attrs.skip_serializing())
|
||||||
.peekable();
|
.peekable();
|
||||||
|
|
||||||
let let_mut = mut_if(serialized_fields.peek().is_some());
|
let let_mut = mut_if(serialized_fields.peek().is_some() ||
|
||||||
|
additional_field_count > 0);
|
||||||
|
|
||||||
let len = serialized_fields
|
let len = serialized_fields
|
||||||
.map(|field| match field.attrs.skip_serializing_if() {
|
.map(|field| match field.attrs.skip_serializing_if() {
|
||||||
|
@ -1413,6 +1413,26 @@ fn test_internally_tagged_struct() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_internally_tagged_braced_struct_with_zero_fields() {
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
struct S {}
|
||||||
|
|
||||||
|
assert_tokens(
|
||||||
|
&S{ },
|
||||||
|
&[
|
||||||
|
Token::Struct {
|
||||||
|
name: "S",
|
||||||
|
len: 1,
|
||||||
|
},
|
||||||
|
Token::Str("type"),
|
||||||
|
Token::Str("S"),
|
||||||
|
Token::StructEnd,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_enum_in_untagged_enum() {
|
fn test_enum_in_untagged_enum() {
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||||
|
Loading…
Reference in New Issue
Block a user