From 5438d1b8e18384a7ae0a0fc6b78c6ab97e434f21 Mon Sep 17 00:00:00 2001 From: Stuart Small Date: Tue, 24 May 2022 16:20:22 -0600 Subject: [PATCH] Parse nulls as None when using serde-well-known Previously when deserializing a json blob that has a field present but set to null it would error with "invalid type: null, expected an RFC3339-formatted `Option`". When the field is present with a value of null serde treats this as Unit. The default implementation always raises a type error. This change parses it as None as a user would expect. --- src/serde/visitor.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/serde/visitor.rs b/src/serde/visitor.rs index bbef85ce41..5b15011c8e 100644 --- a/src/serde/visitor.rs +++ b/src/serde/visitor.rs @@ -291,6 +291,13 @@ impl<'a> de::Visitor<'a> for Visitor> { fn visit_none(self) -> Result, E> { Ok(None) } + + fn visit_unit(self) -> Result + where + E: de::Error, + { + Ok(None) + } } #[cfg(feature = "serde-well-known")] @@ -326,4 +333,11 @@ impl<'a> de::Visitor<'a> for Visitor> { fn visit_none(self) -> Result, E> { Ok(None) } + + fn visit_unit(self) -> Result + where + E: de::Error, + { + Ok(None) + } }