Skip to content

Conversation

@RicoSuter
Copy link
Owner

@RicoSuter RicoSuter commented Oct 2, 2025

Closes #1738

Reverts #1864
and adds a JsonLibraryVersion config instead.

@0xced
Copy link
Contributor

0xced commented Oct 2, 2025

I think the best approach should be to control both attributes independently, from the configuration. Something like new configuration switches named UseEnumMember (defaulting to true to keep compatibility) and UseJsonStringEnumMemberName (defaulting to false for compatibility).

Then users can opt-in to use the new JsonStringEnumMemberName attribute with config.UseJsonStringEnumMemberName = true. This will require either .NET 9 or System.Text.Json 9 for the generated code, hence being opt-in.

Additionally, users can opt-out of the old EnumMember attribute (config.UseEnumMember = false) if they identified that removing it is not an issue.

Note that the tests only asserts that the produced code compiles (CSharpCompiler.AssertCompile(code)) but asserts nothing about the serialized or deserialized JSON using the generated models, see #1738 (comment).

@RicoSuter
Copy link
Owner Author

RicoSuter commented Oct 2, 2025

Yes sorry, its actually a bug in the generator. The EnumValue is actually worthless and can also be removed for STJ, right? In theory yes someone could have implemented a global custom converter

@RicoSuter RicoSuter changed the title fix: JsonStringEnumMemberNameAttriute only for .NET9, EnumMemberAttribute as fallback & tests Add JsonLibraryVersion and generate JsonStringEnumMemberNameAttriute for >= 9.0, EnumMemberAttribute otherwise Nov 5, 2025
@RicoSuter
Copy link
Owner Author

After investigation, the attribute was really working because in NSwag we generate this special converter which handles this correctly. So this was a big breaking change which this PR reverts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support System.Text.Json JsonStringEnumMemberNameAttribute

4 participants