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
The code below demonstrates that flatten and alias features of serde don't work in the toml library.
flatten
alias
toml = "0.5.9"
cargo 1.67.0-nightly (ba607b23d 2022-11-22)
serde = { version = "1.0.147", features = ["derive"] }
Here is an MWE which demonstrates the bug
use serde::Deserialize; #[derive(Deserialize)] struct Inner { #[serde(alias = "myBool")] b: bool, i: i64, } #[derive(Deserialize)] struct Outer { #[serde(flatten)] a: Inner, } #[cfg(test)] mod tests { use super::*; #[test] fn works_as_expected() { let t_str = r#" b = true i = 7 "#; let res: Result<Outer, toml::de::Error> = toml::from_str(t_str); let got = res.unwrap(); assert_eq!(true, got.a.b); assert_eq!(7, got.a.i); } #[test] fn shows_bug() { let t_str = r#" myBool = true i = 7 "#; let res: Result<Outer, toml::de::Error> = toml::from_str(t_str); let got = res.unwrap(); // *** incorrect behavior manifests here assert_eq!(true, got.a.b); assert_eq!(7, got.a.i); } }
The text was updated successfully, but these errors were encountered:
Have you tried reproducing this with other serde formats? I have a feeling that alias is more on the serde_derive side than on the serde format side.
serde_derive
Sorry, something went wrong.
you are correct.
It it happens in serde_json too
serde_json
use serde::Deserialize; #[derive(Deserialize)] struct Inner { #[serde(alias = "myBool")] b: bool, i: i64, } #[derive(Deserialize)] struct Outer { #[serde(flatten)] a: Inner, } #[test] fn works_as_expected() { let t_str = r#" { "b": true, "i": 7 } "#; let res = serde_json::from_str::<Outer>(t_str); let got = res.unwrap(); assert_eq!(true, got.a.b); assert_eq!(7, got.a.i); } #[test] fn shows_bug() { let t_str = r#" { "myBool": true, "i": 7 } "#; let res = serde_json::from_str::<Outer>(t_str); let got = res.unwrap(); // *** incorrect behavior manifests here assert_eq!(true, got.a.b); assert_eq!(7, got.a.i); }
No branches or pull requests
The code below demonstrates that
flatten
andalias
features of serde don't work in the toml library.Env
toml = "0.5.9"
cargo 1.67.0-nightly (ba607b23d 2022-11-22)
serde = { version = "1.0.147", features = ["derive"] }
Here is an MWE which demonstrates the bug
The text was updated successfully, but these errors were encountered: