I created a ASP.NET MVC 4 Web application. Within this application i implemented several rest webservices and here comes my question: Is it possible to force the object serialization to use the enum entity names instead of their values?
This is my enum:
public enum ReturnCode { OK, InvalidParameter }
This is what I get:
{
"returnCode": 0,
"data": null
}
But this is what I want:
{
"returnCode": OK,
"data": null
}
Is there a way to achieve this?
You can use a JsonConverter.
There is a native one for JSON.Net
StringEnumConvertermentioned in this question JSON serialization of enum as stringEither anotate your property:
Or use the config examples in WebApi Json.NET custom date handling to register in the global serialiser settings.