LitJSON / litjson

JSON library for the .Net framework
https://litjson.net/
Other
1.37k stars 404 forks source link

ArgumentException: not of type: Dictionary with Enum as Key #31

Open NVentimiglia opened 9 years ago

NVentimiglia commented 9 years ago

LITJson does not handle serializing/deserializing dictionaries with an enum key. For instance :

public enum MyEnum{
    cat, dog, bird
}

public void Awake(){

    var dic = new Dictionary<MyEnum,int>();

    dic.Add(MyEnum.bird,1);

    // will crash, fix is to change (string)key to key.ToString()  in JsonMapper
    var json = JsonMapper.ToJson(dic);

    // Will also crash
    var dic2 = JsonMapper.ToObject<Dictionary<MyEnum,int>>(json); 
}