Unexpected behavior of time::serde::rfc3339::option::deserialize()
#637
Labels
A-third-party
Area: implementations of traits from other crates
C-enhancement
Category: an enhancement with existing code
When deserializing some data into a struct,
serde
doesn't care if an field with typeOption<T>
is available in the source bytes or not.For example, the following code works fine. It parses an empty json string
{}
as aPasses
instance.I would expect the same behavior for something of type
Option<time::OffsetDateTime>
. But that type behaves different when using thetime::serde::rfc3339::option::deserialize
. Consider the following code. When you run it, it'll panic. The code tries to deserialize an empty{}
as a structFails
. And that fails.serde
claims that fieldsdatetime
is missing. Although the attribute beingOption
al,The failure is:
Is this is bug? Shouldn't
datetime
be set toNone
when the field is not present input that's passed toserde_jsoin:from_value()
?If so, I'm happy to provide a PR to fix the behavior.
Note, I'm aware that I can work around the issue by changing the field attribute of
Fails.datetime
from 'm aware that I can work around#[serde(with = "time::serde::rfc3339::option")]
to#[serde(with = "time::serde::rfc3339::option", default)]
The text was updated successfully, but these errors were encountered: