I'm attempting to get Json.NET to serialize an object and include it's type as follows...
[JsonObject(ItemTypeNameHandling = TypeNameHandling.All)]
public class ABC
{
public string Easy;
public string As;
}
...the following test...
ABC abc = new ABC();
abc.Easy = "123";
abc.As = "do rey me";
string output = JsonConvert.SerializeObject(abc);
...the output is...
{"Easy":"123","As":"do rey me"}
...I was hoping for...
{"$type":"MyTest+ABC, MyTest","Easy":"123","As":"do rey me"}
I'm trying to make selected contracts include type information in a Web API 2 project. Is there no other way to do this than setting it globally? Like so...
config.Formatters.JsonFormatter.SerializerSettings.TypeNameHandling = Newtonsoft.Json.TypeNameHandling.All