For #1429, respect unset initial value on JsonObjectAttribute

This commit is contained in:
Paul Irwin
2017-11-02 11:01:34 -04:00
parent 7d44b61c32
commit 6129124507
2 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -34,11 +34,11 @@ namespace Newtonsoft.Json
public sealed class JsonObjectAttribute : JsonContainerAttribute public sealed class JsonObjectAttribute : JsonContainerAttribute
{ {
private MemberSerialization _memberSerialization = MemberSerialization.OptOut; private MemberSerialization _memberSerialization = MemberSerialization.OptOut;
private NullValueHandling _nullValueHandling = NullValueHandling.Include;
// yuck. can't set nullable properties on an attribute in C# // yuck. can't set nullable properties on an attribute in C#
// have to use this approach to get an unset default state // have to use this approach to get an unset default state
internal Required? _itemRequired; internal Required? _itemRequired;
internal NullValueHandling? _nullValueHandling;
/// <summary> /// <summary>
/// Gets or sets the member serialization. /// Gets or sets the member serialization.
@@ -56,7 +56,7 @@ namespace Newtonsoft.Json
/// <value>The null value handling.</value> /// <value>The null value handling.</value>
public NullValueHandling NullValueHandling public NullValueHandling NullValueHandling
{ {
get => _nullValueHandling; get => _nullValueHandling ?? default(NullValueHandling);
set => _nullValueHandling = value; set => _nullValueHandling = value;
} }
@@ -1511,7 +1511,7 @@ namespace Newtonsoft.Json.Serialization
if (property.NullValueHandling == null && containerAttribute is JsonObjectAttribute objectAttribute) if (property.NullValueHandling == null && containerAttribute is JsonObjectAttribute objectAttribute)
{ {
property.NullValueHandling = objectAttribute.NullValueHandling; property.NullValueHandling = objectAttribute._nullValueHandling;
} }
if (requiredAttribute != null) if (requiredAttribute != null)