using System.Collections.Generic;
using Newtonsoft.Json.Converters;
namespace JsonSerialization
public static void Main(string[] args)
var blobItem = new BlobItem();
var dataItemDic = new TypeYDictionary<IEnumerable<IDataItem>>();
var objDic = new Dictionary<string, object> {{"key", "object"}};
dataItemDic.Add("dataItemKey", new List<DataItem>() { new DataItem() { Attributes = objDic } });
blobItem.TypeXDataDictionary.Add("typeXKey", dataItemDic );
var ser = JsonConvert.SerializeObject(blobItem);
var deSerialized = JsonConvert.DeserializeObject<BlobItem>(ser);
public class TypeConverter<T, TSerialized> : CustomCreationConverter<T>
where TSerialized : T, new()
public override T Create(Type objectType)
return new TSerialized();
Dictionary<string, IValue> SomeValues { get; set; }
public class Value : IValue
[JsonProperty(ItemConverterType = typeof(TypeConverter<IValue, Value>))]
public Dictionary<string, IValue> SomeValues { get; set; }
public interface ISomeAtrributes
Dictionary<string, object> Attributes { get; set; }
public interface IDataItem : ISomeAtrributes
IValue Value { get; set; }
public class DataItem : IDataItem
[JsonProperty(ItemConverterType = typeof(TypeConverter<IValue, Value>))]
public IValue Value { get; set; }
public Dictionary<string, object> Attributes { get; set; }
public interface IBlobItem
TypeXDictionary<IEnumerable<IDataItem>> TypeXDataDictionary { get; set; }
public class BlobItem : IBlobItem
TypeXDataDictionary = new TypeXDictionary<IEnumerable<IDataItem>>();
[JsonProperty(ItemConverterType = typeof(TypeConverter<IEnumerable<IDataItem>, List<DataItem>>))]
public TypeXDictionary<IEnumerable<IDataItem>> TypeXDataDictionary { get; set; }
public class TypeYDictionary<T> : Dictionary<string, T>
public class TypeXDictionary<T> : Dictionary<string, TypeYDictionary<T>>