private static void OverrideReferenceFields(DictionaryBasedEntity entity)
        {
            ICollection <string> keys = new List <string>(entity.GetProperties().Keys);

            foreach (string key in keys)
            {
                object value = entity.GetValue(key);
                if (value is Dictionary <string, object> )
                {
                    Dictionary <string, object> pairValue = (Dictionary <string, object>)value;
                    if (pairValue.ContainsKey("total_count"))//list of entities
                    {
                        EntityList <BaseEntity> entityList = new EntityList <BaseEntity>();
                        IList data = (IList)((Dictionary <string, object>)value)["data"];
                        for (int i = 0; i < data.Count; i++)
                        {
                            Dictionary <string, object> rawEntity = (Dictionary <string, object>)data[i];
                            BaseEntity baseEntity = ConvertToBaseEntity(rawEntity);
                            OverrideReferenceFields(baseEntity);
                            entityList.data.Add(baseEntity);
                        }
                        entity.SetValue(key, entityList);
                    }
                    else //single entity
                    {
                        BaseEntity baseEntity = ConvertToBaseEntity(pairValue);
                        OverrideReferenceFields(baseEntity);
                        entity.SetValue(key, baseEntity);
                    }
                }
            }
        }
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            DictionaryBasedEntity entity = (DictionaryBasedEntity)Activator.CreateInstance(type);

            entity.SetProperties(dictionary);
            OverrideReferenceFields(entity);

            return(entity);
        }
        public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            if (obj == null)
            {
                return(result);
            }
            DictionaryBasedEntity entity = ((DictionaryBasedEntity)obj);

            return(entity.GetProperties());
        }