How to serialize object to json with type info using Newtonsoft.Json?
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
var converters = serializer.Converters.Where(x => !(x is TypeInfoConverter)).ToArray();
var jObject = JObject.FromObject(value);
jObject.AddFirst(new JProperty("Type", value.GetType().Name));
jObject.WriteTo(writer, converters);
}
var jsonSerializerSettings = new JsonSerializerSettings() {
TypeNameHandling = TypeNameHandling.All
};
var json = JsonConvert.SerializeObject(instance, jsonSerializerSettings);
http://james.newtonking.com/json/help/index.html?topic=html/SerializationSettings.htm