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 together.
flatten
alias
Below shows examples from both serde_json and toml library.
serde_json
toml
toml = "0.5.9"
serde_json = "1.0.89"
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_in_toml() { 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_in_toml() { 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); } #[test] fn works_as_expected_in_json() { let j_str = r#" { "b": true, "i": 7 } "#; let res = serde_json::from_str::<Outer>(j_str); let got = res.unwrap(); assert_eq!(true, got.a.b); assert_eq!(7, got.a.i); } #[test] fn shows_bug_in_json() { let j_str = r#" { "myBool": true, "i": 7 } "#; let res = serde_json::from_str::<Outer>(j_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:
This is a known problem: #1504.
Sorry, something went wrong.
This was fixed (partially) by #2387, the in-place part is fixed in #2443
Closing as a duplicate of #2188.
No branches or pull requests
The code below demonstrates that
flatten
andalias
features of serde don't work together.Below shows examples from both
serde_json
andtoml
library.Env
toml = "0.5.9"
serde_json = "1.0.89"
cargo 1.67.0-nightly (ba607b23d 2022-11-22)
serde = { version = "1.0.147", features = ["derive"] }
Here is an MWE which demonstrates the bug
Related
The text was updated successfully, but these errors were encountered: