I discovered the other day that the DataContractJsonSerializer ignores the [EnumMember] attribute. If it encounters a enum value it will always use the integer value of the enum.
For example if I define the following data contracts...
public enum VehicleType
[EnumMember(Value = "Car")]
[EnumMember(Value = "Bike")]
public class MyDataContract
public VehicleType Vehicle
... and return a MyDataContract with Vehicle set to VehicleType.Bike it will be serialised in Json as 1. If I use the standard Xml serialiser it will be serialised to my specified value of 'Bike'.
This is specified in
this MSDN article as the intended behaviour, but it seems a bit strange to me and a little bit frustrating. I could probably spend time writing my own serialiser to do this, but it seems like a feature that should be there in the framework.
Is there a good reason why this serialiser ignores the [EnumMember] attributes? If not could this be changed in a future release?
Twitter Please "mark as answer" if this answers the question.. thanks!
View Complete Post