Restore EnumMemberAttribute for .net10#655
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #655 +/- ##
=======================================
Coverage 78.64% 78.64%
=======================================
Files 98 98
Lines 2548 2548
Branches 425 425
=======================================
Hits 2004 2004
Misses 434 434
Partials 110 110 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@abergs sorry, we need to restore this attribute :) |
|
@vpetrusevici Have we verified that the original issue is still resolved when EnumMember is added? And, is there a way to add tests to confirm the proper behavior in serialization? |
|
Yes. I'll try to add test, including Newtonsoft |
…serialization tests
tests added |
|
@abergs anything else? :) |
|
All good, preview.3 will be rolling out. |
|
@abergs hi! did you release it? |
|
@abergs, preview.3 is still unavailable :( |
|
@vpetrusevici Seems there was a github issue while running tests. Running everything again. |
Summary
This PR updates the attribute pattern used for enum members across the project to ensure full compatibility with both
System.Text.Json(specifically in .NET 9+) andNewtonsoft.Json.Problem
Previously, enum members used a conditional
#if NET9_0_OR_GREATERblock with an#elseclause that toggled between[JsonStringEnumMemberName]and[EnumMember].While this worked for
System.Text.Json, it broke compatibility withNewtonsoft.Json(and tools like NSwag that rely on it) when running on .NET 9+. SinceNewtonsoft.Jsondoes not recognize[JsonStringEnumMemberName], it would fall back to default naming, leading to serialization mismatches in environments whereSystem.Text.Jsonis not the primary serializer.Solution
The
#elseblock has been removed, making[EnumMember]unconditional.[JsonStringEnumMemberName]remains wrapped in#if NET9_0_OR_GREATERto take advantage of native .NET 9 features while preserving the metadata needed by other libraries.New Pattern:
Key Changes
#elsefrom enum member attributes in all model files.[EnumMember]is always present for every enum member.#iflogic forJsonConverterdeclarations and internal logic where appropriate.