-Remove IgnoreAll and move fix to Ignore
This commit is contained in:
@@ -84,7 +84,7 @@
|
|||||||
<content>
|
<content>
|
||||||
<para><codeEntityReference>T:Newtonsoft.Json.DefaultValueHandling</codeEntityReference>
|
<para><codeEntityReference>T:Newtonsoft.Json.DefaultValueHandling</codeEntityReference>
|
||||||
is an option on the JsonSerializer and controls how the serializer handles
|
is an option on the JsonSerializer and controls how the serializer handles
|
||||||
properties with a default value. Setting a value of DefaultValueHandling.IgnoreAll
|
properties with a default value. Setting a value of DefaultValueHandling.Ignore
|
||||||
will make the JsonSerializer skip writing any properties that have a default
|
will make the JsonSerializer skip writing any properties that have a default
|
||||||
value to the JSON result. For object references this will be null. For value
|
value to the JSON result. For object references this will be null. For value
|
||||||
types like int and DateTime the serializer will skip the default uninitialized
|
types like int and DateTime the serializer will skip the default uninitialized
|
||||||
|
|||||||
@@ -130,12 +130,8 @@
|
|||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<entry><para><legacyBold>Ignore</legacyBold></para></entry>
|
<entry><para><legacyBold>Ignore</legacyBold></para></entry>
|
||||||
<entry><para>Json.NET will skip writing a field/property value to JSON if the value is null or is the same as the value specified in field/property's <codeEntityReference>T:System.ComponentModel.DefaultValueAttribute</codeEntityReference>. The Json.NET deserializer will skip setting a .NET object's field/property if the JSON value is the same as the default value.</para></entry>
|
|
||||||
</row>
|
|
||||||
<row>
|
|
||||||
<entry><para><legacyBold>IgnoreAll</legacyBold></para></entry>
|
|
||||||
<entry><para>Json.NET will skip writing a field/property value to JSON if the value is the same as the field/property's default value, or the custom
|
<entry><para>Json.NET will skip writing a field/property value to JSON if the value is the same as the field/property's default value, or the custom
|
||||||
value specified in <codeEntityReference>T:System.ComponentModel.DefaultValueAttribute</codeEntityReference> if it is present. The Json.NET deserializer
|
value specified in <codeEntityReference>T:System.ComponentModel.DefaultValueAttribute</codeEntityReference> if the attribute is present. The Json.NET deserializer
|
||||||
will skip setting a .NET object's field/property if the JSON value is the same as the default value.</para></entry>
|
will skip setting a .NET object's field/property if the JSON value is the same as the default value.</para></entry>
|
||||||
</row>
|
</row>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -725,7 +725,7 @@ namespace Newtonsoft.Json.Tests.Documentation
|
|||||||
|
|
||||||
string ignored = JsonConvert.SerializeObject(invoice,
|
string ignored = JsonConvert.SerializeObject(invoice,
|
||||||
Formatting.Indented,
|
Formatting.Indented,
|
||||||
new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.IgnoreAll });
|
new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
|
||||||
|
|
||||||
// {
|
// {
|
||||||
// "Company": "Acme Ltd.",
|
// "Company": "Acme Ltd.",
|
||||||
|
|||||||
@@ -78,18 +78,8 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
Assert.AreEqual(@"{
|
Assert.AreEqual(@"{
|
||||||
""Company"": ""Acme Ltd."",
|
""Company"": ""Acme Ltd."",
|
||||||
""Amount"": 50.0,
|
|
||||||
""Paid"": false
|
|
||||||
}", ignored);
|
|
||||||
|
|
||||||
string ignoredAll = JsonConvert.SerializeObject(invoice,
|
|
||||||
Formatting.Indented,
|
|
||||||
new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.IgnoreAll });
|
|
||||||
|
|
||||||
Assert.AreEqual(@"{
|
|
||||||
""Company"": ""Acme Ltd."",
|
|
||||||
""Amount"": 50.0
|
""Amount"": 50.0
|
||||||
}", ignoredAll);
|
}", ignored);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -221,7 +211,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
json = JsonConvert.SerializeObject(c, Formatting.Indented, new JsonSerializerSettings
|
json = JsonConvert.SerializeObject(c, Formatting.Indented, new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
DefaultValueHandling = DefaultValueHandling.IgnoreAll
|
DefaultValueHandling = DefaultValueHandling.Ignore
|
||||||
});
|
});
|
||||||
|
|
||||||
Assert.AreEqual(@"{
|
Assert.AreEqual(@"{
|
||||||
@@ -247,7 +237,7 @@ namespace Newtonsoft.Json.Tests.Serialization
|
|||||||
|
|
||||||
public class DefaultValueHandlingPropertyClass
|
public class DefaultValueHandlingPropertyClass
|
||||||
{
|
{
|
||||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAll)]
|
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
|
||||||
public int IntIgnore { get; set; }
|
public int IntIgnore { get; set; }
|
||||||
|
|
||||||
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)]
|
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)]
|
||||||
|
|||||||
@@ -45,9 +45,10 @@ namespace Newtonsoft.Json
|
|||||||
Include = 0,
|
Include = 0,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ignore members where the member value is the same as the member's default value when serializing objects
|
/// Ignore members where the member value is the same as the member's default value when serializing objects
|
||||||
/// so that is is not written to JSON. This option will only ignore <c>null</c> values for object and nullable types
|
/// so that is is not written to JSON.
|
||||||
/// unless the property explicitly has a <see cref="DefaultValueAttribute"/> specified. To ignore default values
|
/// This option will ignore all default values (e.g. <c>null</c> for objects and nullable typesl; <c>0</c> for integers,
|
||||||
/// for all types use the <c>IgnoreAll</c> option.
|
/// decimals and floating point numbers; and <c>false</c> for booleans). The default value ignored can be override by
|
||||||
|
/// the <see cref="DefaultValueAttribute"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Ignore = 1,
|
Ignore = 1,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -58,14 +59,6 @@ namespace Newtonsoft.Json
|
|||||||
/// Ignore members where the member value is the same as the member's default value when serializing objects
|
/// Ignore members where the member value is the same as the member's default value when serializing objects
|
||||||
/// and sets members to their default value when deserializing.
|
/// and sets members to their default value when deserializing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
IgnoreAndPopulate = Ignore | Populate,
|
IgnoreAndPopulate = Ignore | Populate
|
||||||
/// <summary>
|
|
||||||
/// Ignore members where the member value is the same as the member's default value when serializing objects
|
|
||||||
/// so that is is not written to JSON, and ignores setting members when the JSON value equals the member's default value.
|
|
||||||
/// This option will ignore all default values (e.g. <c>null</c> for objects and nullable typesl; <c>0</c> for integers,
|
|
||||||
/// decimals and floating point numbers; and <c>false</c> for booleans). The default value ignored can be override by
|
|
||||||
/// the <see cref="DefaultValueAttribute"/>.
|
|
||||||
/// </summary>
|
|
||||||
IgnoreAll = 4
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -209,7 +209,7 @@ namespace Newtonsoft.Json
|
|||||||
get { return _defaultValueHandling; }
|
get { return _defaultValueHandling; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value < DefaultValueHandling.Include || value > DefaultValueHandling.IgnoreAll)
|
if (value < DefaultValueHandling.Include || value > DefaultValueHandling.IgnoreAndPopulate)
|
||||||
throw new ArgumentOutOfRangeException("value");
|
throw new ArgumentOutOfRangeException("value");
|
||||||
|
|
||||||
_defaultValueHandling = value;
|
_defaultValueHandling = value;
|
||||||
|
|||||||
@@ -976,7 +976,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
{
|
{
|
||||||
property._required = (dataMemberAttribute.IsRequired) ? Required.AllowNull : Required.Default;
|
property._required = (dataMemberAttribute.IsRequired) ? Required.AllowNull : Required.Default;
|
||||||
property.Order = (dataMemberAttribute.Order != -1) ? (int?) dataMemberAttribute.Order : null;
|
property.Order = (dataMemberAttribute.Order != -1) ? (int?) dataMemberAttribute.Order : null;
|
||||||
property.DefaultValueHandling = (!dataMemberAttribute.EmitDefaultValue) ? (DefaultValueHandling?) DefaultValueHandling.IgnoreAll : null;
|
property.DefaultValueHandling = (!dataMemberAttribute.EmitDefaultValue) ? (DefaultValueHandling?) DefaultValueHandling.Ignore : null;
|
||||||
hasMemberAttribute = true;
|
hasMemberAttribute = true;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -204,13 +204,7 @@ namespace Newtonsoft.Json.Serialization
|
|||||||
memberValue == null)
|
memberValue == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
DefaultValueHandling defaultValueHandling = property.DefaultValueHandling.GetValueOrDefault(Serializer.DefaultValueHandling);
|
if (HasFlag(property.DefaultValueHandling.GetValueOrDefault(Serializer.DefaultValueHandling), DefaultValueHandling.Ignore)
|
||||||
|
|
||||||
if (HasFlag(defaultValueHandling, DefaultValueHandling.Ignore)
|
|
||||||
&& MiscellaneousUtils.ValueEquals(memberValue, property.DefaultValue))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (defaultValueHandling == DefaultValueHandling.IgnoreAll
|
|
||||||
&& MiscellaneousUtils.ValueEquals(memberValue, property.DefaultValue ?? ReflectionUtils.GetDefaultValue(property.PropertyType)))
|
&& MiscellaneousUtils.ValueEquals(memberValue, property.DefaultValue ?? ReflectionUtils.GetDefaultValue(property.PropertyType)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user