KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
When I serialize a enum value using DataContractJsonSerializer, it serializes the numerical value of the enum, not the string name. IE: enum foo { bar, baz } Serializing a value of foo.bar returns "0", not "bar". I'd prefer it the other way around, is there a way to override this? Edit: Because I didn't want to change the serializer, I used a simple workaround hack. I exposed a property in the class to serialize that calls ToString on the value, ie: // Old [DataMember] public EnumType Foo { get { return _foo; } set { _foo = value; } } // New, I still kept the EnumType but I only serialize the string version public EnumType Foo { get { return _foo; } set { _foo = value; } } [DataMember] public string FooType { get { return _foo.ToString(); } private set {} }
Tags (comma-separated)
Save Edits
Cancel