Skip to content
New issue

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

Support deserializing flattened untagged enum #1253

Closed
r8d8 opened this issue May 10, 2018 · 2 comments
Closed

Support deserializing flattened untagged enum #1253

r8d8 opened this issue May 10, 2018 · 2 comments

Comments

@r8d8
Copy link

r8d8 commented May 10, 2018

Getting error while flattening enum inside struct:

value: Error("can only flatten structs and maps", line: 6, column: 5)'

Source code: https://gist.github.com/r8d8/2940b5490a90204e5052809eae9b8868

serde version 1.0.51

@dtolnay dtolnay changed the title Enum flattening produces error Support deserializing flattened untagged enum May 10, 2018
@dtolnay
Copy link
Member

dtolnay commented May 10, 2018

Thanks. Minimized:

#[macro_use]
extern crate serde_derive;

extern crate serde;
extern crate serde_json;

#[derive(Deserialize, Debug)]
struct KdfParams {
    #[serde(flatten)]
    kdf: Kdf,
}

#[derive(Deserialize, Debug)]
#[serde(untagged)]
enum Kdf {
    Pbkdf2 {
        c: u32,
    },
}

fn main() {
    let j = r#" {"c":0} "#;
    println!("{}", serde_json::from_str::<KdfParams>(j).unwrap_err());
}

@dtolnay
Copy link
Member

dtolnay commented May 10, 2018

I released Serde 1.0.53 with a fix -- after a cargo update your code should work as written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants