mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-04-22 22:58:02 +00:00
serialize tuple enums with single element directly as the value instead of a sequence
This commit is contained in:
@@ -28,7 +28,7 @@ enum Animal {
|
||||
Dog,
|
||||
Frog(String, Vec<isize>),
|
||||
Cat { age: usize, name: String },
|
||||
|
||||
AntHive(Vec<String>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
@@ -534,6 +534,10 @@ fn test_write_enum() {
|
||||
Animal::Cat { age: 5, name: "Kate".to_string() },
|
||||
"{\"Cat\":{\"age\":5,\"name\":\"Kate\"}}"
|
||||
),
|
||||
(
|
||||
Animal::AntHive(vec!["Bob".to_string(), "Stuart".to_string()]),
|
||||
"{\"AntHive\":[\"Bob\",\"Stuart\"]}",
|
||||
),
|
||||
]);
|
||||
|
||||
test_pretty_encode_ok(&[
|
||||
@@ -976,6 +980,10 @@ fn test_parse_enum() {
|
||||
" { \"Cat\" : { \"age\" : 5 , \"name\" : \"Kate\" } } ",
|
||||
Animal::Cat { age: 5, name: "Kate".to_string() },
|
||||
),
|
||||
(
|
||||
" { \"AntHive\" : [\"Bob\", \"Stuart\"] } ",
|
||||
Animal::AntHive(vec!["Bob".to_string(), "Stuart".to_string()]),
|
||||
),
|
||||
]);
|
||||
|
||||
test_parse_ok(vec![
|
||||
|
||||
Reference in New Issue
Block a user