Is it possible to serialize the enum as either a proper string value or the value specified by the EnumMember attribute rather than a number? It seems that JSON serialization ignores the Value property of EnumMember attribute. If I change WebMessageFormat to Xml it works fine, but I need to use JSON.
I have the following IIS-Hosted REST Service
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json,
UriTemplate = "test")]
SomeObject Test();
SomeObject:
[DataContract]
public class SomeObject
{
[DataMember]
public SomeEnum FooBar
{
get;
set;
}
}
SomeEnum:
[DataContract]
public enum SomeEnum
{
[EnumMember(Value = "FooValue")]
[Description("FooDescription")]
Foo,
[EnumMember(Value = "BarValue")]
[Description("BarDescription")]
Bar,
}
What I get:
{"FooBar":0}
I'd like to get one of the following (preferably the first, but either one works):
{"FooBar": "FooValue"}
{"FooBar": "Foo"}