-Remove IgnoreAll and move fix to Ignore

This commit is contained in:
James Newton-King
2012-09-01 14:08:11 +12:00
parent d9c8d78d77
commit 2320d2d55e
8 changed files with 14 additions and 41 deletions
+1 -1
View File
@@ -84,7 +84,7 @@
<content>
<para><codeEntityReference>T:Newtonsoft.Json.DefaultValueHandling</codeEntityReference>
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
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
+1 -5
View File
@@ -130,12 +130,8 @@
</row>
<row>
<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
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>
</row>
</table>
@@ -725,7 +725,7 @@ namespace Newtonsoft.Json.Tests.Documentation
string ignored = JsonConvert.SerializeObject(invoice,
Formatting.Indented,
new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.IgnoreAll });
new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore });
// {
// "Company": "Acme Ltd.",
@@ -78,18 +78,8 @@ namespace Newtonsoft.Json.Tests.Serialization
Assert.AreEqual(@"{
""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
}", ignoredAll);
}", ignored);
}
[Test]
@@ -221,7 +211,7 @@ namespace Newtonsoft.Json.Tests.Serialization
json = JsonConvert.SerializeObject(c, Formatting.Indented, new JsonSerializerSettings
{
DefaultValueHandling = DefaultValueHandling.IgnoreAll
DefaultValueHandling = DefaultValueHandling.Ignore
});
Assert.AreEqual(@"{
@@ -247,7 +237,7 @@ namespace Newtonsoft.Json.Tests.Serialization
public class DefaultValueHandlingPropertyClass
{
[JsonProperty(DefaultValueHandling = DefaultValueHandling.IgnoreAll)]
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public int IntIgnore { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)]
+5 -12
View File
@@ -45,9 +45,10 @@ namespace Newtonsoft.Json
Include = 0,
/// <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. This option will only ignore <c>null</c> values for object and nullable types
/// unless the property explicitly has a <see cref="DefaultValueAttribute"/> specified. To ignore default values
/// for all types use the <c>IgnoreAll</c> option.
/// so that is is not written to JSON.
/// 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>
Ignore = 1,
/// <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
/// and sets members to their default value when deserializing.
/// </summary>
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
IgnoreAndPopulate = Ignore | Populate
}
}
+1 -1
View File
@@ -209,7 +209,7 @@ namespace Newtonsoft.Json
get { return _defaultValueHandling; }
set
{
if (value < DefaultValueHandling.Include || value > DefaultValueHandling.IgnoreAll)
if (value < DefaultValueHandling.Include || value > DefaultValueHandling.IgnoreAndPopulate)
throw new ArgumentOutOfRangeException("value");
_defaultValueHandling = value;
@@ -976,7 +976,7 @@ namespace Newtonsoft.Json.Serialization
{
property._required = (dataMemberAttribute.IsRequired) ? Required.AllowNull : Required.Default;
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;
}
#endif
@@ -204,13 +204,7 @@ namespace Newtonsoft.Json.Serialization
memberValue == null)
return false;
DefaultValueHandling defaultValueHandling = property.DefaultValueHandling.GetValueOrDefault(Serializer.DefaultValueHandling);
if (HasFlag(defaultValueHandling, DefaultValueHandling.Ignore)
&& MiscellaneousUtils.ValueEquals(memberValue, property.DefaultValue))
return false;
if (defaultValueHandling == DefaultValueHandling.IgnoreAll
if (HasFlag(property.DefaultValueHandling.GetValueOrDefault(Serializer.DefaultValueHandling), DefaultValueHandling.Ignore)
&& MiscellaneousUtils.ValueEquals(memberValue, property.DefaultValue ?? ReflectionUtils.GetDefaultValue(property.PropertyType)))
return false;