Open OrangeTux opened 7 months ago
This has been brought up before, and I'm not aware of how to fix it. My recommendation has always been to use #[serde(default)]
. If there is a better way, I'm more than happy to review a PR.
Related #562
Thanks for the response. I'll have try to find a fix. Bit since you're aware of the issue and don't know a solution, I'm doubt that I'll fine a solution.
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)]