Merge branch 'master' of https://github.com/vontangen/Newtonsoft.Json into vontangen-master

This commit is contained in:
James Newton-King
2015-10-12 20:27:21 +13:00
2 changed files with 26 additions and 0 deletions
@@ -235,6 +235,11 @@ namespace Newtonsoft.Json.Serialization
/// </summary>
/// <value>A predicate used to determine whether the property should be serialize.</value>
public Predicate<object> ShouldSerialize { get; set; }
/// <summary>
/// Gets or sets a predicate used to determine whether the property should be de-serialized.
/// </summary>
/// <value>A predicate used to determine whether the property should be de-serialized.</value>
public Predicate<object> ShouldDeSerialize { get; set; }
/// <summary>
/// Gets or sets a predicate used to determine whether the property should be serialized.
@@ -2051,6 +2051,15 @@ namespace Newtonsoft.Json.Serialization
continue;
}
if (!ShouldDeSerialize(reader, property, newObject))
{
if (!reader.Read())
break;
SetExtensionData(contract, member, reader, memberName, newObject);
continue;
}
if (property.PropertyContract == null)
property.PropertyContract = GetContractSafe(property.PropertyType);
@@ -2096,7 +2105,19 @@ namespace Newtonsoft.Json.Serialization
OnDeserialized(reader, contract, newObject);
return newObject;
}
//reader, contract, member, id
private bool ShouldDeSerialize(JsonReader reader, JsonProperty property, object target)
{
if (property.ShouldDeSerialize == null)
return true;
bool shouldDeSerialize = property.ShouldDeSerialize(target);
if (TraceWriter != null && TraceWriter.LevelFilter >= TraceLevel.Verbose)
TraceWriter.Trace(TraceLevel.Verbose, JsonPosition.FormatMessage(null, reader.Path, "ShouldDeSerialize result for property '{0}' on {1}: {2}".FormatWith(CultureInfo.InvariantCulture, property.PropertyName, property.DeclaringType, shouldDeSerialize)), null);
return shouldDeSerialize;
}
private bool CheckPropertyName(JsonReader reader, string memberName)
{
if (Serializer.MetadataPropertyHandling == MetadataPropertyHandling.ReadAhead)