Closed Kazy closed 1 year ago
This behavior is documented in the docs for time::serde::format_description!
here:
The returned
Option
will contain a deserialized value if present andNone
if the field is present but the value isnull
(or the equivalent in other formats). To returnNone
when the field is not present, you should use#[serde(default)]
on the field.
@jhpratt This isn't the issue here, unless I'm deeply misunderstanding something. If you look at the second example, it returns an error in presence of a null
value, even though in the first example the same struct but not this time not part of an enum correctly deserializes to None
.
I expect the second example to be Ok(Inner(Inner { date: None } ))
, just like the third one but with a None
since the value of date
is null
.
@Kazy did you find a workaround? We're currently blocked at the same issue. Adding #[serde(default)]
didn't help.
I think this should be re-opened (though if you re-open it now, it won't incentivize me to produce a minimal repro…)
I've hit this: specifically, at the top (nesting) level of the json object, null
values are deserialized to None
. At levels below, the parser fails. I implemented the code that the macro creates, and made further modifications. I was able to operate on the top and the next level, but not the one below that. I have not taken the time to grasp serde's recursive structure: I think someone with such experience will be able to spot what is missing, in short order.
Hello !
I've encountered a bug when trying to deserialize to an
Option<PrimitiveDateTime>
using thetime::serde::format_description!
macro. When the struct containing the optional datetime is part of an enum, it fails when receiving anull
value. When deserializing to the inner structure directly or when the value isn'tnull
everything works as expected.Here is a reproduction of the issue. This has been reproduced on 0.3.9, 0.3.20, and the current Git master (c644bd2847c0a111c595b6d9a2935f990a267525)
Result:
Thank you for your help !