using System.Collections.Generic;
public static void Main()
""$type"": ""MyRootType"",
""SysMandantId"": ""0005fe04-424a-43e4-aed0-2e9650abc021"",
""MyCollectionProperty"": {
""$type"": ""MyCollectionSurrogate"",
""PropertyName"": ""MyCollectionProperty"",
""RecordsetId"": ""1e241c5f-1d39-42b4-b2c2-8d8abd03deee"",
""$type"": ""System.Collections.Generic.List`1[[MyItem]], mscorlib"",
""Id"": ""08433367-f9f7-4ab8-b7ef-9560b0b4b7aa""
""Id"": ""ba4fcff4-3262-471c-a38d-f66f98d36d00""
var tmpSettings = new JsonSerializerSettings
ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
PreserveReferencesHandling = PreserveReferencesHandling.Objects,
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Include,
TypeNameHandling = TypeNameHandling.Objects | TypeNameHandling.Arrays,
Binder = new MySerializationBinder()
tmpSettings.Converters.Add(new MyCollectionConverter());
var tmpDeserializedObject = JsonConvert.DeserializeObject<MyRootType>(json, tmpSettings);
public MyCollection MyCollectionProperty { get; set; }
public string Title { get; set; }
public class MyCollectionSurrogate
public String PropertyName { get; set; }
public Guid RecordsetId { get; set; }
public List<MyItem> Items { get; set; }
public class MyCollection
public String PropertyName { get; set; }
public Guid RecordsetId { get; set; }
public List<MyItem> Items { get; set; }
public Guid Id { get; set; }
public class MySerializationBinder : Newtonsoft.Json.Serialization.DefaultSerializationBinder
private Dictionary<String, String> KnownCoreTypes = new Dictionary<string, string>
{"MyCollectionSurrogate", "Root" }
public override Type BindToType(string assemblyName, string typeName)
Type tmpTypeToDeserialize = null;
if (KnownCoreTypes.TryGetValue(typeName, out tmpActualValue) && tmpActualValue == assemblyName)
if (typeName.Equals("MyCollectionSurrogate"))
typeName = "MyCollection";
var tmpCurrentAssembly = typeof(MySerializationBinder).GetTypeInfo().Assembly;
foreach (var tmpType in tmpCurrentAssembly.DefinedTypes)
if (!tmpType.FullName.Split('.').Last().Equals(typeName.Split('.').Last()))
typeName = tmpType.FullName;
assemblyName = tmpCurrentAssembly.FullName;
tmpTypeToDeserialize = Type.GetType(String.Format("{0}, {1}", typeName, assemblyName));
return tmpTypeToDeserialize;
public class MyCollectionConverter : JsonConverter
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
var tmpCollection = (MyCollection)value;
var tmpSurrogate = new MyCollectionSurrogate()
RecordsetId = tmpCollection.RecordsetId,
PropertyName = tmpCollection.PropertyName,
Items = tmpCollection.Items
serializer.Serialize(writer, tmpSurrogate);
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
var tmpSurrogate = serializer.Deserialize<MyCollectionSurrogate>(reader);
var tmpItems = tmpSurrogate.Items;
var tmpMyCollection = new MyCollection()
PropertyName = tmpSurrogate.PropertyName,
RecordsetId = tmpSurrogate.RecordsetId
public override bool CanConvert(Type objectType)
return objectType == typeof(MyCollection);