Overriding global serialization options with JsonConverterAttribute
behaves unexpectedly
#102712
Labels
JsonConverterAttribute
behaves unexpectedly
#102712
Description
It seems like applying the
[JsonConverter(typeof(JsonNumberEnumConverter<TEnum>))]
on the enum level does not override the global serializer options. Based on my own understanding (and then later a confirmation in this comment) the attribute allows falling back to number serialization in case the global options specifies a default of string serialization.In my case, I don't want to serialize flags to string as that makes it harder to handle flags in the frontend. Added the attribute on the enum type itself and started plucking my hair out since that wouldn't work no matter what. Then added the attribute on the property instead and voila, then it works.
Reproduction contains a NUnit test which covers both working and not working cases.
Reproduction Steps
Expected behavior
Converter specified on type level overrides the global converter settings.
Actual behavior
Converter specified on type level does not override the global converter settings.
Regression?
No response
Known Workarounds
No response
Configuration
.NET version: 8.0.204
OS: Ubuntu 23.10
I do not think OS has any impact, to be honest.
Other information
No response
The text was updated successfully, but these errors were encountered: