Skip to content

Conversation

Mingun
Copy link
Contributor

@Mingun Mingun commented Sep 19, 2025

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

@Mingun Mingun force-pushed the default-variant branch 2 times, most recently from 5d7e6bf to 9a4f396 Compare September 19, 2025 15:06
…gged enums

If tag will not be found in the data, the default tag will be assumed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Optional tag for internally tagged enum #[serde(default)] as a variant attribute for when the tag is not present Default tag.
1 participant