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
You need to add #[serde(default)] as an attribute to the contents field too. It is the normal behavior for serde to disable the special treatment regarding missing fields whenever a with annotation is added. The serde_as is equivalent to the with in this regard.
There is an issue to maybe change that in the future #185.
470: Simplify `serde_as` handling around `Option`s r=jonasbb a=jonasbb
Using `#[serde_as]` on a field of type `Option` changes the behavior, in that the field can no longer be missing.
This often times was unexpected and lead to confusion (e.g., #183, #185, #311, #417).
Now if both the field and the transformation type are `Option` the `#[serde(default)]` attribute is added. `Option`s are identified by exact text matches and these variants are supported:
* `Option`
* `std::option::Option`, with or without leading `::`
* `core::option::Option`, with or without leading `::`
If a `default` attribute already exists nothing happens. This new behavior can be suppressed by using `#[serde_as(no_default)]` on the field. If the transformation type is not `Option`, e.g., like `NoneAsEmptyString`, nothing happens either.
Closes#185
Co-authored-by: Jonas Bushart <jonas@bushart.org>
I have this code which fails. I believe it should be supported.
It serializes fine with a single element in a vector or multiple elements in a vector
It fails with an error when the contents are set to None
failures:
---- tests::vec_none stdout ----
None
Serialized ---
{}
Error: Message("missing field
contents
", Some(Pos { marker: Marker { index: 4, line: 2, col: 0 }, path: "." }))Please find a test case attached.
Workaround: Dont specify #[skip_serializing_none]
test.txt
The text was updated successfully, but these errors were encountered: