I have a filter object in C#, that contains a dictionary of strings (that represent the propery name) and the corresponding value (expecting an object).
When sending an object of a custom type with JSON to WCF, I use __type
in my JSON to deserialize correctly from the JSON object to a C# object. However, when sending a enum (represented as integer in JSON) this will be serialized as integer in C#, because the deserializer has no way of telling what kind of enum it is expecting.
The JSON I send:
{
"filterList": [
{ "FilterProperty": "Status", "FilterValue": 4 }
{ "FilterProperty": "Status", "FilterValue": 6 }
]
}
The DataContract it deserializes to a list of these:
public class Filter
{
[DataMember]
public string FilterProperty { get; set; }
[DataMember]
public object FilterValue { get; set; }
}
The FilterValue corresponds in this specific situation with the an enum. But because the FilterValue property is defined as object, the deserializer does not know how to deserialize it without additional information.
Is it possible to send additional information with JSON to let WCF correctly deserialize the enum even if an object is expected?
Or is the only way to solve this to use reflection to resolve the type from the filter property name?