You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("missing field `optional_bar`", line: 0, column: 0)', src/libcore/result.rs:1165:5
and it is not clear to me why that would be the case. Or rather, it seems incorrect that it does.
then deserialization succeeds. If I am reading correctly between the lines then we may end up treating the fact that there is a deserialize_with attribute as: the corresponding field has to exist. That seems bogus.
(if my hypothesis is correct, I suppose as a work around I could create a newtype wrapping Option<Bar> and implement Deserialize on it and that may solve the issue, but I haven't tried that yet [and I am not particularly eager to work around the issue this way because I simply can't have newtypes like this everywhere])
The text was updated successfully, but these errors were encountered:
I think I've hit the same problem, and it was surprising. I've just addedd #[serde(default)] and I think that solves the problem for me in this particular case.
Using deserialize_with does turn off the Option-specific special case that deals with the field being absent, as you found. Adding serde(default) is the no-longer-Option-specific way to get back that behavior.
Please have a look at the following example:
(playground)
This code fails with
and it is not clear to me why that would be the case. Or rather, it seems incorrect that it does.
If I apply the following patch:
then deserialization succeeds. If I am reading correctly between the lines then we may end up treating the fact that there is a
deserialize_with
attribute as: the corresponding field has to exist. That seems bogus.(if my hypothesis is correct, I suppose as a work around I could create a newtype wrapping
Option<Bar>
and implementDeserialize
on it and that may solve the issue, but I haven't tried that yet [and I am not particularly eager to work around the issue this way because I simply can't have newtypes like this everywhere])The text was updated successfully, but these errors were encountered: