Allow empty string identifiers on non-flags enums in JsonStringEnumConverter#128285
Draft
Copilot wants to merge 3 commits into
Draft
Allow empty string identifiers on non-flags enums in JsonStringEnumConverter#128285Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
…nverter Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/b77c051c-b5f7-4943-9c20-6e4fe34c3b37 Co-authored-by: eiriktsarpalis <[email protected]>
Copilot
AI
changed the title
[WIP] Fix JsonStringEnumMemberNameAttribute to support empty strings
Allow empty string identifiers on non-flags enums in JsonStringEnumConverter
May 16, 2026
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-text-json |
| [JsonStringEnumMemberName("n")] | ||
| No, | ||
|
|
||
| [JsonStringEnumMemberName("")] |
Member
There was a problem hiding this comment.
@copilot unless it already exists, please add test coverage for a similar flags enum.
Contributor
Author
There was a problem hiding this comment.
Added EnumWithEmptyStringMemberName_Flags_Throws with a YesOrNoOrEmptyFlags companion to YesOrNoOrEmpty, asserting that the empty-string identifier is still rejected for [Flags] enums on both serialize and deserialize. Commit 36a53ea.
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/e6c2eed7-d610-4d2a-ba79-80c4760a113d Co-authored-by: eiriktsarpalis <[email protected]>
Copilot
AI
requested review from
Copilot and
eiriktsarpalis
and removed request for
Copilot
May 18, 2026 13:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
[JsonStringEnumMemberName("")]was rejected at runtime for all enums, even though the empty-string ambiguity it was guarding against only applies to[Flags]enums (e.g."y, , n"). This blocked common interop scenarios where an XSD-derived enum has a member whose XML/JSON representation is the empty string.Description
EnumConverter.ResolveAndValidateJsonName: relaxed the guard so empty strings are permitted on non-flags enums. Flags enums continue to reject empty identifiers (parsing ambiguity) and commas.nulland leading/trailing whitespace remain rejected for both — input isTrim()-normalized before lookup, so allowing those would silently break round-tripping.Strings.resx: updatedUnsupportedEnumIdentifierto describe the new rule ("It must not be null nor contain leading or trailing whitespace. Flags enums must additionally not be empty nor contain commas.").EnumWithInvalidMemberName2(empty identifier) is now marked[Flags]so it continues to validate the remaining rejection path.EnumWithEmptyStringMemberName_NonFlags_RoundtripsAsExpectedcovering serialize/deserialize for"y","n", and""against the issue'sYesOrNoOrEmptyenum.EnumWithEmptyStringMemberName_Flags_Throwswith a companion[Flags]YesOrNoOrEmptyFlagsenum, asserting that the empty-string identifier is still rejected on both serialize and deserialize for flags enums.Note
This pull request was created by an AI agent (GitHub Copilot Coding Agent) on behalf of the user.