Support #[serde(default)] as a variant attribute for when the tag is not present #2985
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Yes, I know, that the relevant issue was closed, but because people ask for it again and again, and because the implementation is only in few lines, I made it.
Now you can place
#[serde(default)]
attribute on variant of internally tagged enum and if the tag is missing in map representation, then it would be assumed as default. Attribute does not change the seq representation of enum, because this create ambiguity when the first field of the content would be interpreted as a tag.It seems that the
#[serde(default)]
attribute may also be supported for adjacently tagged enums, but that requires a bit more work and very likely to will conflict with #2935, so I left that for another PR.Fixes #1410, fixes #1799, fixes #2231, closes #2476