-
Notifications
You must be signed in to change notification settings - Fork 260
Closed
Description
Using the json5 format, null values are not handled in JSON input. The json format handles this correctly.
The following code fails:
const JSON: &str = r#"
{
"name": "string",
"optional": null
}
"#;
let file = config::File::from_str(JSON, config::FileFormat::Json5);
let config = Config::builder().add_source(file).build().unwrap();
// called `Result::unwrap()` on an `Err` value: invalid type: unit value, expected a boolean, integer, float, string, null, array or mapThe error seems to be caused by a missing handler for unit in the Deserialize implementation for the json5 Val type:
// json5.rs, line 18:
impl<'de> serde::de::Deserialize<'de> for Val {
fn deserialize<D>(d: D) -> Result<Self, D::Error>
where
D: serde::de::Deserializer<'de>,
{
serde_untagged::UntaggedEnumVisitor::new()
.bool(|value| Ok(Self::Boolean(value)))
.i64(|value| Ok(Self::Integer(value)))
.f64(|value| Ok(Self::Float(value)))
.string(|value| Ok(Val::String(value.to_owned())))
.none(|| Ok(Self::Null))
.unit(|| Ok(Self::Null)) // Adding this allows parsing of null values !
.seq(|value| value.deserialize().map(Val::Array))
.map(|value| value.deserialize().map(Val::Object))
.deserialize(d)
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels