@@ -1318,9 +1318,24 @@ mod content {
1318
1318
where
1319
1319
V : Visitor < ' de > ,
1320
1320
{
1321
+ // Covered by tests/test_enum_internally_tagged.rs
1322
+ // newtype_unit
1321
1323
match self . content {
1322
- Content :: Unit => visitor. visit_unit ( ) ,
1323
-
1324
+ // As a special case, allow deserializing untagged newtype
1325
+ // variant containing unit struct.
1326
+ //
1327
+ // #[derive(Deserialize)]
1328
+ // struct Info;
1329
+ //
1330
+ // #[derive(Deserialize)]
1331
+ // #[serde(tag = "topic")]
1332
+ // enum Message {
1333
+ // Info(Info),
1334
+ // }
1335
+ //
1336
+ // We want {"topic":"Info"} to deserialize even though
1337
+ // ordinarily unit structs do not deserialize from empty map/seq.
1338
+ //
1324
1339
// Allow deserializing newtype variant containing unit.
1325
1340
//
1326
1341
// #[derive(Deserialize)]
@@ -1331,7 +1346,8 @@ mod content {
1331
1346
//
1332
1347
// We want {"result":"Success"} to deserialize into Response<()>.
1333
1348
Content :: Map ( ref v) if v. is_empty ( ) => visitor. visit_unit ( ) ,
1334
- _ => Err ( self . invalid_type ( & visitor) ) ,
1349
+ Content :: Seq ( ref v) if v. is_empty ( ) => visitor. visit_unit ( ) ,
1350
+ _ => self . deserialize_any ( visitor) ,
1335
1351
}
1336
1352
}
1337
1353
@@ -1343,25 +1359,9 @@ mod content {
1343
1359
where
1344
1360
V : Visitor < ' de > ,
1345
1361
{
1346
- match self . content {
1347
- // As a special case, allow deserializing untagged newtype
1348
- // variant containing unit struct.
1349
- //
1350
- // #[derive(Deserialize)]
1351
- // struct Info;
1352
- //
1353
- // #[derive(Deserialize)]
1354
- // #[serde(tag = "topic")]
1355
- // enum Message {
1356
- // Info(Info),
1357
- // }
1358
- //
1359
- // We want {"topic":"Info"} to deserialize even though
1360
- // ordinarily unit structs do not deserialize from empty map/seq.
1361
- Content :: Map ( ref v) if v. is_empty ( ) => visitor. visit_unit ( ) ,
1362
- Content :: Seq ( ref v) if v. is_empty ( ) => visitor. visit_unit ( ) ,
1363
- _ => self . deserialize_any ( visitor) ,
1364
- }
1362
+ // Covered by tests/test_enum_internally_tagged.rs
1363
+ // newtype_unit_struct
1364
+ self . deserialize_unit ( visitor)
1365
1365
}
1366
1366
1367
1367
fn deserialize_newtype_struct < V > (
0 commit comments