I'm getting data in json format from different sources and I'm trying to map them to objects implementing the same interface.
The json variable looks something like this from feed 1:
{"identifier": 232, "type": "Feed1"}
And I'm serializing it using this object:
[DataContract]
public class Class A : InterfaceA
{
[DataMember(Name = "identifier")]
public int Id{ get; set; }
[DataMember(Name = "type")]
public FeedType Type { get; set; }
}
[DataContract]
public enum FeedType
{
[EnumMember(Value = "Feed1")]
FeedA,
[EnumMember(Value = "Feed2")]
FeedB,
[EnumMember(Value = "Feed3")]
FeedC
}
The interface looks like this:
public interface InterfaceA
{
int Id {get;set;}
FeedType Type{get;set;}
}
In feed 2, the object looks like this:
{"identifier": 232, "feedType": "A"}
How can I create another object that implements the same interface and will return the same enum? How do I set up the DataContract?
EDIT:
I serialize it like this
var serializer = new DataContractJsonSerializer(ClassA);
var ms = new MemoryStream(Encoding.Unicode.GetBytes(json));
var serializedObject = serializer.ReadObject(ms);