My question is simple, but a little more specific than other issues related to serializing enumerated types as strings.
Consider the following code snippet:
using Newtonsoft.Json; using Newtonsoft.Json.Converters; public enum MyEnum { TypeOne, TypeTwo, TypeThree } public class Foo { [JsonConverter(typeof(StringEnumConverter))] public MyEnum Types { get; set; } }
When the web API controller sends serialized Foo objects, they might look something like this:
{ "Type" : "TypeTwo" }
My question is: is it possible to send serialized enumerations in the form of strings with spaces before each capital letter? Such a solution would create JSON as follows:
{ "Type" : "Type Two" }
Let me know if there is any additional information needed to solve my problem. Thanks!
EDIT:
This is preferable if the enumerations only convert to strings with spaces, and serialize them to JSON. I would like to eliminate spaces using MyEnum.ToString() on the server.
json enums c # serialization asp.net-web-api
The brogrammer
source share