mgholam / fastJSON

Smallest, fastest polymorphic JSON serializer
https://www.codeproject.com/Articles/159450/fastJSON-Smallest-Fastest-Polymorphic-JSON-Seriali
MIT License
478 stars 148 forks source link

Cannot deserialize Dictionary<int, List<double>> #99

Closed xmedeko closed 5 years ago

xmedeko commented 5 years ago

fastJSON fails deserialize a field Dictionary<int, List<double>> or a field Dictionary<int, double[]> . I have UseExtensions = false. It fails with:

System.InvalidCastException: Object must implement IConvertible.
  at System.Convert.ChangeType (System.Object value, System.Type conversionType, System.IFormatProvider provider) [0x00055] in <1f0c1ef1ad524c38bbc5536809c46b48>:0 
  at fastJSON.deserializer.ChangeType (System.Object value, System.Type conversionType) [0x00246] in ...\fastJSON\JSON.cs:541 
  at fastJSON.deserializer.CreateDictionary (System.Collections.Generic.List`1[T] reader, System.Type pt, System.Type[] types, System.Collections.Generic.Dictionary`2[TKey,TValue] globalTypes) [0x000d9] in ...\fastJSON\JSON.cs:902 
  at fastJSON.deserializer.ParseDictionary (System.Collections.Generic.Dictionary`2[TKey,TValue] d, System.Collections.Generic.Dictionary`2[TKey,TValue] globaltypes, System.Type type, System.Object input) [0x00463] in ...\fastJSON\JSON.cs:738 
...

Note: serialization is ok.

mgholam commented 5 years ago

Thanks, I will look into it.

mgholam commented 5 years ago

The following works for me, what is your test case?

        var d = new Dictionary<string, List<double>>();
        d.Add("a", new List<double> { 1, 2, 3 });
        d.Add("b", new List<double> { 4, 5, 6 });
        var s = JSON.ToJSON(d, new JSONParameters { UseExtensions = false });

        var o = JSON.ToObject<Dictionary<string, List<double>>>(s);
xmedeko commented 5 years ago

Sorry, it's Dictionary<int, List<double>> and Dictionary<int, double[]> what is failing. (I have originally enum as a key in my code.)

mgholam commented 5 years ago

fixed in v2.2.3