I am using Web API service. My class is as follows
public class MyClass
{
public Dictionary<MyClass, List<MyClass>> MyDataDictionary { get; set; }
public string Id { get; set; }
public string Name { get; set; }
public MyClass(string id, string name)
{
Id = id;
Name = name;
}
}
I am facing problem with serialization of dictionary Key, which is composite type MyClass. When WebAPI returns MyClass instance, I see that dictionary key are not serialised, instead its type (MyNamespace.MyClass) is present there.
MyClassObj.MyDataDictionary.Add(new MyClass("1", "Name1") , List);
Always List is serialized. why not Key Object, how to fix it?
{
"Id":2,"Name":"Unknown",
"MyDataDictionary":{
"*MyNamespace.MyClass*":[
{
"Id":2, "Name":"Th/Abd",
"MyDataDictionary ":null
}
]
}
}