Json deserializer always returns an object even when no fields were present, but other calling code was expecting a null to be returned if deserialization failed.

Deserializer now only instantiates object when at least 1 field was found, otherwise null is returned
This commit is contained in:
Ryan Gribble
2016-07-05 22:53:30 +10:00
committed by Brendan Forster
parent f5359cdf7c
commit cd503f2c67
+6 -1
View File
@@ -1486,12 +1486,17 @@ namespace Octokit
obj = value;
else
{
obj = ConstructorCache[type]();
foreach (KeyValuePair<string, KeyValuePair<Type, ReflectionUtils.SetDelegate>> setter in SetCache[type])
{
object jsonValue;
if (jsonObject.TryGetValue(setter.Key, out jsonValue))
{
// Create object if it hasn't been created yet
if (obj == null)
{
obj = ConstructorCache[type]();
}
jsonValue = DeserializeObject(jsonValue, setter.Value.Key);
setter.Value.Value(obj, jsonValue);
}