using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
using System.Collections.Specialized;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
class Attribute2 : Attribute1
public static void Main()
var serializerSettings = new JsonSerializerSettings()
TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Full,
TypeNameHandling = TypeNameHandling.Objects,
Formatting = Formatting.Indented,
attr1 = new Attribute2(),
attr2 = new Attribute2(),
string serializedClass2 = JsonConvert.SerializeObject(a, serializerSettings);
Console.WriteLine("Json: ");
Console.WriteLine(serializedClass2);
var am = JsonConvert.DeserializeObject<class2>(serializedClass2);
Console.WriteLine("Deserialized class2 without TypeNameHandling.Objects: ");
Console.WriteLine("attr1.GetType() = {0}, attr2.GetType() = {1}", am.attr1.GetType(), am.attr2.GetType());
var am2 = JsonConvert.DeserializeObject<class2>(serializedClass2, serializerSettings);
Console.WriteLine("Deserialized class2 WITH TypeNameHandling.Objects: ");
Console.WriteLine("attr1.GetType() = {0}, attr2.GetType() = {1}", am2.attr1.GetType(), am2.attr2.GetType());