Skip to content

Commit 0626f61

Browse files
Erik Bylundkirre-bylund
authored andcommitted
fix: Fix for generic object member parsing
ZeroDepJSON failed to parse members of a defined object if those members are of generic object type because it tried to use reflection on the member which the generic object won't have.
1 parent 0d0f1fd commit 0626f61

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Runtime/Libraries/ZeroDepJson/ZeroDepJson.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Text;
1414
using System.Text.RegularExpressions;
1515
using System.Xml.Serialization;
16+
using UnityEngine;
1617

1718
#pragma warning disable IDE0063 // Use simple 'using' statement
1819
#pragma warning disable IDE0057 // Use range operator
@@ -275,6 +276,10 @@ private static object CreateInstance(object target, Type type, int elementsCount
275276
var elementType = type.GetElementType();
276277
return Array.CreateInstance(elementType, elementsCount);
277278
}
279+
if(typeof(String) == type)
280+
{
281+
return String.Empty;
282+
}
278283
return Activator.CreateInstance(type);
279284
}
280285
catch (Exception e)
@@ -1797,6 +1802,14 @@ public virtual void ApplyEntry(IDictionary dictionary, object target, string key
17971802

17981803
if (value is IDictionary dic)
17991804
{
1805+
// If the Type (the member field type inside of the encapsulating object) is a generic object then it won't have mappable fields to parse to.
1806+
// Instead we simply set it to the parsed value
1807+
if (Type == typeof(object))
1808+
{
1809+
var oValue = ChangeType(target, value, Type, options);
1810+
Accessor.Set(target, oValue);
1811+
return;
1812+
}
18001813
var targetValue = GetOrCreateInstance(target, dic.Count, options);
18011814
Apply(dic, targetValue, options);
18021815
return;
@@ -5116,7 +5129,7 @@ public virtual void AddException(Exception error)
51165129
throw new ArgumentNullException(nameof(error));
51175130

51185131
if (_exceptions.Count >= MaximumExceptionsCount)
5119-
throw new JsonException("JSO0015: Two many JSON errors detected (" + _exceptions.Count + ").", error);
5132+
throw new JsonException("JSO0015: Too many JSON errors detected (" + _exceptions.Count + ").", error);
51205133

51215134
_exceptions.Add(error);
51225135
}

0 commit comments

Comments
 (0)