Merge branch 'master' of https://github.com/vontangen/Newtonsoft.Json into vontangen-master
This commit is contained in:
@@ -235,6 +235,11 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>A predicate used to determine whether the property should be serialize.</value>
|
/// <value>A predicate used to determine whether the property should be serialize.</value>
|
||||||
public Predicate<object> ShouldSerialize { get; set; }
|
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>
|
/// <summary>
|
||||||
/// Gets or sets a predicate used to determine whether the property should be serialized.
|
/// Gets or sets a predicate used to determine whether the property should be serialized.
|
||||||
|
|||||||
@@ -2051,6 +2051,15 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ShouldDeSerialize(reader, property, newObject))
|
||||||
|
{
|
||||||
|
if (!reader.Read())
|
||||||
|
break;
|
||||||
|
|
||||||
|
SetExtensionData(contract, member, reader, memberName, newObject);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (property.PropertyContract == null)
|
if (property.PropertyContract == null)
|
||||||
property.PropertyContract = GetContractSafe(property.PropertyType);
|
property.PropertyContract = GetContractSafe(property.PropertyType);
|
||||||
|
|
||||||
@@ -2096,7 +2105,19 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
OnDeserialized(reader, contract, newObject);
|
OnDeserialized(reader, contract, newObject);
|
||||||
return 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)
|
private bool CheckPropertyName(JsonReader reader, string memberName)
|
||||||
{
|
{
|
||||||
if (Serializer.MetadataPropertyHandling == MetadataPropertyHandling.ReadAhead)
|
if (Serializer.MetadataPropertyHandling == MetadataPropertyHandling.ReadAhead)
|
||||||
|
|||||||
Reference in New Issue
Block a user