Skip to content

Commit

Permalink
Parse nulls as None when using serde-well-known
Browse files Browse the repository at this point in the history
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<OffsetDateTime>`".  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.
  • Loading branch information
stusmall committed May 24, 2022
1 parent aec5caa commit 5438d1b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/serde/visitor.rs
Expand Up @@ -291,6 +291,13 @@ impl<'a> de::Visitor<'a> for Visitor<Option<well_known::Rfc2822>> {
fn visit_none<E: de::Error>(self) -> Result<Option<OffsetDateTime>, E> {
Ok(None)
}

fn visit_unit<E>(self) -> Result<Self::Value, E>
where
E: de::Error,
{
Ok(None)
}
}

#[cfg(feature = "serde-well-known")]
Expand Down Expand Up @@ -326,4 +333,11 @@ impl<'a> de::Visitor<'a> for Visitor<Option<well_known::Rfc3339>> {
fn visit_none<E: de::Error>(self) -> Result<Option<OffsetDateTime>, E> {
Ok(None)
}

fn visit_unit<E>(self) -> Result<Self::Value, E>
where
E: de::Error,
{
Ok(None)
}
}

0 comments on commit 5438d1b

Please sign in to comment.