-
-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should serde_as
apply default
when the field is of type Option<_>
#185
Labels
enhancement
New feature or request
Comments
jonasbb
added a commit
that referenced
this issue
Jun 5, 2022
…store support for missing fields A `with` or `deserialize_with` on an `Option` field removes the ability to allow missing fields. This modification detects if the field is `Option` and the transformation is `Option<T>`. In this case it is likely that the missing field behavior is desired. A `no_default` can be added to supress this new behavior. This commit does not include any documentation changes. Closes #185
bors bot
added a commit
that referenced
this issue
Jun 6, 2022
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>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using
deserialize_with
orserde_as
on aOption
field makes them mandatory while deserializing. In order to make the behavior match more closely with the default serde behavior,serde_as
could apply thedefault
attribute on the field. This would make the field optional again while deserializing.The downside would be that is complicates the macro and would introduce additional behavior.
Right now it only translates the
serde_as
attribute into serde'sdeserialize_with
andserialize_with
.Originally proposed in #183
Related to #184
The text was updated successfully, but these errors were encountered: