JsonConverterAttribute cannot be applied to an Enum #30361
Labels
area-System.Text.Json
enhancement
Product code improvement that does NOT require public API changes/additions
Milestone
Since I'm trying to migrate from
Newtonsoft.Json
to the newSystem.Text.Json
APIs, I have to be able to use a Enum-string converter.In json.net you can do this really easily with this attribute on the enum.
Since there is both a JsonConverterAttribute and a JsonStringEnumConverter class, I thought you would do it like this:
However after getting a compiler error I quickly realized that the
JsonConverterAttribute
can't even be used on an Enum because it only has the following threeAttributeTargets
-flags.AttributeTargets.Class
AttributeTargets.Struct
AttributeTargets.Property
Are you not supposed to use this attribute and converter like this?
Are there any samples because there I've not found any in the docs?
The text was updated successfully, but these errors were encountered: