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
If I define a struct with a tag and add a field with the "flatten" attribute to this struct. The structs's tag seems to be ignored.
extern crate serde; // 1.0.84 #[macro_use] extern crate serde_derive; // 1.0.84 #[macro_use] extern crate serde_json; // 1.0.34 #[derive(Serialize, Debug)] #[serde(tag="type")] pub struct Program { #[serde(flatten)] pub body: ProgramType } #[derive(Serialize, Debug)] #[serde(tag="sourceType", content="body")] pub enum ProgramType { #[serde(rename="script")] Script(u64), } fn main() { let p = Program{body: ProgramType::Script(0)}; // This assert fails, output: // left: `Object({"body": Number(0), "sourceType": String("script")})`, // right: `Object({"body": Number(0), "sourceType": String("script"), "type": String("Program")})` assert_eq!(serde_json::to_value(p).unwrap(), json!({"type": "Program", "sourceType": "script", "body": 0})) }
The text was updated successfully, but these errors were encountered:
Thanks! This looks like a bug. Would you be interested in sending a PR to fix it?
Sorry, something went wrong.
Sure. I implemented the tagged structs in the first place so I guess it's only fair if I have to do the bug fixing :D But it might take a few days.
1d6ef76
Merge pull request #1474 from jwillbold/master
6a3a820
Fixed #1468, flattened struct fields made structs ignore their tag
No branches or pull requests
If I define a struct with a tag and add a field with the "flatten" attribute to this struct. The structs's tag seems to be ignored.
The text was updated successfully, but these errors were encountered: