-Changed DataContractAttribute on collections back to array serialization

-Fixed JObject.GetPropertyOwner to return value
-Fixed JPropertyDescriptor GetValue and SetValue to return null for null owner
This commit is contained in:
James Newton-King
2018-03-12 15:43:28 +13:00
parent 4f1aa395db
commit c72f785b9c
6 changed files with 57 additions and 21 deletions
+5
View File
@@ -780,6 +780,11 @@ namespace Newtonsoft.Json.Linq
object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor pd)
{
if (pd is JPropertyDescriptor)
{
return this;
}
return null;
}
#endregion
@@ -69,9 +69,7 @@ namespace Newtonsoft.Json.Linq
/// <param name="component">The component with the property for which to retrieve the value.</param>
public override object GetValue(object component)
{
JToken token = CastInstance(component)[Name];
return token;
return (component as JObject)?[Name];
}
/// <summary>
@@ -89,9 +87,12 @@ namespace Newtonsoft.Json.Linq
/// <param name="value">The new value.</param>
public override void SetValue(object component, object value)
{
JToken token = value as JToken ?? new JValue(value);
if (component is JObject o)
{
JToken token = value as JToken ?? new JValue(value);
CastInstance(component)[Name] = token;
o[Name] = token;
}
}
/// <summary>
@@ -1176,15 +1176,6 @@ namespace Newtonsoft.Json.Serialization
return CreateDictionaryContract(objectType);
}
#if HAVE_DATA_CONTRACTS
// don't use GetDataContractAttribute because it looks for the attribute on base classes
DataContractAttribute dataContractAttribute = JsonTypeReflector.GetCachedAttribute<DataContractAttribute>(objectType);
if (dataContractAttribute != null)
{
return CreateObjectContract(objectType);
}
#endif
if (t == typeof(JToken) || t.IsSubclassOf(typeof(JToken)))
{
return CreateLinqContract(objectType);