json
json copied to clipboard
Deserialize empty map into None
I have a JSON format which could be either a tagged value or an empty map {}. Examples of JSON:
{"A" : 123}
{"B" : 234}
{}
I want to deserialize it into a enum, so I defined one:
#[derive(Debug, Serialize, Deserialize)]
enum Enum {
A(i64),
B(i64),
#[serde(other)]
None,
}
Despite having one option labeled with #[serde(other)] de-serialization fails for {} .
Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=dd5719ccc279964cc65d545a2261a177
This needs to be fixed in serde's Deserialize derive macro, not serde-json. You could repost this issue there: https://github.com/serde-rs/serde/issues/