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

Value::Null should always be able to deserialize into Option::None #532

stevenroose opened this Issue Apr 5, 2019 · 1 comment


2 participants
Copy link

stevenroose commented Apr 5, 2019

In my opinion, when having an Option<T> with T: serde::Deserialize, it should always be possible to deserialize a serde_json::Value::Null into the None variant.

F.e. this should work:

let opt: Option<String> = serde_json::from_value(serde_json::Value::Null).unwrap();
assert_eq!(opt, None);

Currently I'm getting errors for this. Would it be possible to make sure this is always possible? When using structs, we can use the #[serde(default)] tag which, while cumbersome, can workaround this. But when not using structs, a more complex match is required.


This comment has been minimized.

Copy link

dtolnay commented Apr 5, 2019

I believe this is how serde_json already works. Playground of the code in your comment

@dtolnay dtolnay closed this Apr 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.