The combination of `StringEnumConverter` and `EnumMember` does not work
I try to have "speaking values" for my enum values in a JSON file. I tried combining the both annotations from the title, but it does not work and I cannot understand why. Maybe you know something I missed out :).
Enum
Model (shortend)
Converter call
15 Replies
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
yeah, the converter does not respect the EnumMember attribute
if you google, you can find a custom converter which respects it, which you can paste into your project and use instead of StringEnumConverter
https://github.com/dotnet/runtime/issues/74385#issuecomment-1705083109
@TeBeClone yep, you're right. I need to have a "readable" json file, but I want type-safety in my C# code.
@reflectronic thanks for the tip!
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
I guess you're right from where I come aka Swift, there's a simple build-in string representation for enums, I think I have to learn more than just the code 😄
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
yep
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
At least I'm not the onloy one who fall into this "trap": https://github.com/dotnet/runtime/issues/74385#issuecomment-1727384007
GitHub
Support customizing enum member names in System.Text.Json · Issue #...
Issue 31081 was closed in favor of issue 29975, however the scope of the issues differ. Issues 29975 is a discussion regarding the DataContract and DataMember attributes in general. Although JsonSt...
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
As a swift developer, enums are mighty AF with payloads, type-safety, etc. The C# word is a bit basic 😄
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
w00t?!
Unknown User•7mo ago
Message Not Public
Sign In & Join Server To View
thanks for the insights!