By default when you return an enum value as part of your data contract in ASP.NET Core, it will be serialized as a number value.
Here is an example of our data contract:
And how it will be returned by our API:
But what if we want to return the enum value as a string instead of a number?
We can achieve this by updating our JsonOptions and register the JsonStringEnumConverter
:
If we now call our API, the result looks like this: