diff --git a/JotunnLib/Utils/SimpleJson.cs b/JotunnLib/Utils/SimpleJson.cs index 5bcea8812..de8042d58 100644 --- a/JotunnLib/Utils/SimpleJson.cs +++ b/JotunnLib/Utils/SimpleJson.cs @@ -1,4 +1,4 @@ -//----------------------------------------------------------------------- +//----------------------------------------------------------------------- // // Copyright (c) 2011, The Outercurve Foundation. // @@ -1387,6 +1387,19 @@ public virtual object DeserializeObject(object value, Type type) ? Convert.ChangeType(value, type, CultureInfo.InvariantCulture) : value; } + else if (value is JsonArray && ReflectionUtils.IsTypeDictionary(type)) + { + var jarray = (JsonArray)value; + + Type[] types = ReflectionUtils.GetGenericTypeArguments(type); + Type keyType = types[0]; + Type valueType = types[1]; + Type genericType = typeof(Dictionary<,>).MakeGenericType(keyType, valueType); + IDictionary dict = (IDictionary)ConstructorCache[genericType](); + + foreach (JsonObject elem in jarray) dict.Add(DeserializeObject(elem[0], keyType), DeserializeObject(elem[1], valueType)); + obj = dict; + } else { IDictionary objects = value as IDictionary; @@ -1416,7 +1429,10 @@ public virtual object DeserializeObject(object value, Type type) obj = value; else { - obj = ConstructorCache[type](); + var constructorDelegate = ConstructorCache[type]; + if (constructorDelegate != null) obj = constructorDelegate(); + else throw new MissingMethodException($"No default constructor found for {type}"); + foreach (KeyValuePair> setter in SetCache[type]) { object jsonValue;