I know there are options to serialize Type info in Json.Net.
We can add type info to json object as $type property.
But both TypeNameHandling.Objects and TypeNameHandling.Array options increase message size dramatically.
I need to serialize root element type info. I have complex object and I need only main object type info.
How can I achieve it? Could I write new TypeNameHandling or how?
SAMPLE C# OBJECTS AND DESIRED JSON RESULT
public class MainComplexObject
{
public int Id { get; set; }
public IEnumerable<B> BList { get; set; }
}
public class B
{
public int Id { get; set; }
public string Name { get; set; }
public C C { get; set; }
}
public class C
{
}
We want to serialize MainComplexObject, desired Json result:
{"$type":"ns.MyComplexObject, ...","Id":3,BList:[{"Id":85,"Name":"...","C":{...}]}
Only MainComplexObject type is written to Json. There is no type info except that.
Edit For @dbc 's comment:
All classed (MyComplexObject,B,C,..) have Interfaces.
NOTE
I want to deserialize it to correct type (MyComplexObject) also.