0

There is a question about generically converting enums to/from strings. This questions is a little different.

Is there a way in an ASP.NET Web API 2 app to define the controller API for a call where it will receive/return JSON where the property is a string in the JSON, but it is declared as an enum?

Community
  • 1
  • 1
David Thielen
  • 28,723
  • 34
  • 119
  • 193
  • possible duplicate of [JSON serialization of c# enum as string](http://stackoverflow.com/questions/2441290/json-serialization-of-c-sharp-enum-as-string) – nawfal Jul 17 '14 at 09:22

1 Answers1

1

If you are using JSON.NET, you can use the following attribute for your Enum object-

[JsonConverter(typeof(StringEnumConverter))]

Check this link.

NomadTraveler
  • 1,086
  • 1
  • 12
  • 37