mgholam / fastJSON

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

GenericsClass<Dictionary<string, IList<T>>> #28

Closed johnearnshaw closed 8 years ago

johnearnshaw commented 8 years ago

Hey guys,

I've been stuck with this issue for a couple of days and found a work around to my problem...

Attempting to deserialize a generic class where T is a dictionary<string, List> was trying to map the List as List

Changing lines 835 and 836 of JSON.cs (inside the CreateStringKeyDictionary method) to the code below fixed the issue but probably not the most elegant of fixes and probably not the most ideal place to put the change.

else if (values.Value is IList) { var t = t2.GetGenericArguments()[0]; val = CreateGenericList((List<object>)values.Value, t2, t, globalTypes); }

The problem was that the collection is created from t2 but t1 is typeof(System.String), when it needed to be the generic arg of t2 (the IList)

mgholam commented 8 years ago

Thanks John!

Do you have sample code for this which I can put in a test?