serde-yaml
serde-yaml copied to clipboard
Deserialize empty map and default value
I have this code
use std::collections::HashMap;
use serde::Deserialize;
#[derive(Deserialize, Debug)]
#[serde(default)]
struct Request {
m: HashMap<String, String>
}
impl Default for Request {
fn default() -> Self {
Self {
m: Default::default(),
}
}
}
fn main() {
let json = r#"
m:
"#;
let requests: Request = serde_yaml::from_str(json).unwrap();
println!("{:?}", requests);
}
I'd expect the Request.m
to be an empty map.
but it actually throws:
value: Message("invalid type: unit value, expected a map", Some(Pos { marker: Marker { index: 12, line: 4, col: 0 }, path: "m" }))
why it's showing as uint
?
can I get an empty map in this case?
playgroud: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f2b451c3a8e43672a1e8632afcab23db
thanks
Fixed in 0.9.7.