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

Confusing error message when deserializing a simple enum from JSON #2702

Open
avandecreme opened this issue Feb 19, 2024 · 0 comments
Open

Comments

@avandecreme
Copy link

With a simple enum type like this one:

#[derive(Debug, Deserialize)]
enum Foo {
    Bar, Baz,
}

If the json passed does not have the correct type, the error message is confusing. For example:

    let bool_foo = serde_json::from_str::<Foo>("true");
    println!("Bool foo: {:?}", bool_foo);
   // This prints: Bool foo: Err(Error("expected value", line: 1, column: 1))

I would expect the error message to tell that the type is a boolean instead of the expected string.

See the following playground to reproduce together with a custom Deserialize implementation which behave more like I would expect: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=be6d3c0aa282ae7ee1bf5d9748709f4b

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

No branches or pull requests

1 participant