diff --git a/serde/src/private/de.rs b/serde/src/private/de.rs index c58fc587b..91998163e 100644 --- a/serde/src/private/de.rs +++ b/serde/src/private/de.rs @@ -1287,8 +1287,9 @@ mod content { // } // // We want {"topic":"Info"} to deserialize even though - // ordinarily unit structs do not deserialize from empty map. + // ordinarily unit structs do not deserialize from empty map/seq. Content::Map(ref v) if v.is_empty() => visitor.visit_unit(), + Content::Seq(ref v) if v.is_empty() => visitor.visit_unit(), _ => self.deserialize_any(visitor), } } diff --git a/test_suite/tests/test_macros.rs b/test_suite/tests/test_macros.rs index c6c0c1785..4d67a6479 100644 --- a/test_suite/tests/test_macros.rs +++ b/test_suite/tests/test_macros.rs @@ -994,6 +994,28 @@ fn test_internally_tagged_struct_variant_containing_unit_variant() { Token::StructEnd, ], ); + + assert_de_tokens( + &Message::Log { level: Level::Info }, + &[ + Token::Map { len: Some(2) }, + Token::Str("action"), + Token::Str("Log"), + Token::Str("level"), + Token::BorrowedStr("Info"), + Token::MapEnd, + ], + ); + + assert_de_tokens( + &Message::Log { level: Level::Info }, + &[ + Token::Seq { len: Some(2) }, + Token::Str("Log"), + Token::BorrowedStr("Info"), + Token::SeqEnd, + ], + ); } #[test] @@ -1877,6 +1899,25 @@ fn test_internally_tagged_newtype_variant_containing_unit_struct() { Token::MapEnd, ], ); + + assert_de_tokens( + &Message::Info(Info), + &[ + Token::Struct { name: "Message", len: 1 }, + Token::Str("topic"), + Token::Str("Info"), + Token::StructEnd, + ], + ); + + assert_de_tokens( + &Message::Info(Info), + &[ + Token::Seq { len: Some(1) }, + Token::Str("Info"), + Token::SeqEnd, + ], + ); } #[deny(safe_packed_borrows)]