Serialize Enum as String for Requests and Responses in ASP.NET Core
Configure a global converter
builder.Services.AddControllers()
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
});
Or you could just annotate the property with this attribute if you don't want it applied to all properties in your app
public class User
{
...
[JsonConverter(typeof(JsonStringEnumConverter))]
public Gender Gender { get; set; }
...
}
This will return enums as their string representations. It will also accept strings and map them to the enum if they match exactly (case insensitive (I think? I'm not sure))