We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serde relies by default to externally tagged for enum variants. For example:
#[derive(Debug,Deserialize,PartialEq,Serialize)] enum StringOrNumber { String(String), Number(u64), } #[test] fn to_json() { assert_eq!( r#" { "Number": 42 } "#.trim(), serde_json::to_string_pretty(&StringOrNumber::Number(42)).unwrap(), ); } #[test] fn from_json() { assert_eq!( StringOrNumber::Number(42), serde_json::from_str(r#" { "Number": 42 } "#).unwrap(), ); }
Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c2ca0468b627ea6491eab5c122273ca3
However, you can't parse it from YAML-impl while:
Demonstration:
#[derive(Debug,Deserialize,PartialEq,Serialize)] enum StringOrNumber { String(String), Number(u64), } #[test] fn to_yaml() { assert_eq!( r#" Number: 42 "#.trim_start(), serde_yaml::to_string(&StringOrNumber::Number(42)).unwrap(), ); } #[test] fn from_json() { assert_eq!( StringOrNumber::Number(42), serde_yaml::from_str(r#" { "Number": 42 } "#).unwrap(), ); } #[test] fn from_yaml() { assert_eq!( StringOrNumber::Number(42), serde_yaml::from_str(r#" Number: 42 "#).unwrap(), ); }
Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e23c1abf4cb53373edb08862b69d7d4e
I have also initialized a crate to reference any other issues: https://github.com/loganmzz/serde-yaml-ng-compatibility-issues
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Serde relies by default to externally tagged for enum variants. For example:
Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c2ca0468b627ea6491eab5c122273ca3
However, you can't parse it from YAML-impl while:
Demonstration:
Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e23c1abf4cb53373edb08862b69d7d4e
I have also initialized a crate to reference any other issues: https://github.com/loganmzz/serde-yaml-ng-compatibility-issues
The text was updated successfully, but these errors were encountered: