Enums and JSON.NET 4.5 Using [DataContract] attributes

Apr 27, 2012 at 12:16 AM

Hello,

I have an Enum defined something like

public MyEnum{
 ONE,
 TWO,
}

I'm trying to get Enums to serialize as "ONE", "TWO", not "0", "1".  

I have tried:  
  JsonSerializerSettings settings = new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore };
  settings.Converters.Add(new StringEnumConverter());
  var data = JsonConvert.SerializeObject(item, Formatting.Indented, settings);

but this does not seem to work. I think the issue is I'm using [DataMember] on my properties.

Is it expected behavior to ignore the StringEnumConverter on properties decorated with [DataMember]?

Thanks in advance,
Jon

May 2, 2012 at 12:21 PM

i am struggling the same. I got the reply with "read the documentation".

I can read object browser output but to find the way to solve our problem by reading the object browser-output is not my way to go...

So I am stuck too...