Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/Newtonsoft.Json.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJamesNK <james@newtonking.com>2011-04-10 06:53:43 +0400
committerJamesNK <james@newtonking.com>2011-04-10 06:53:43 +0400
commit48f3242095d9eb2fcd0b5ddf9bcfd44bbf445ab6 (patch)
treef77f22f1fdcd93c4d31e53bc6986e2ec562d5887 /Src/Newtonsoft.Json
parent1ab8f8b6867a60889cfe7ae9f78a16a585c0a425 (diff)
-Fixed DefaultValueHandling including a property when the default value is the same value but a different type
Diffstat (limited to 'Src/Newtonsoft.Json')
-rw-r--r--Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs2
-rw-r--r--Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs2
-rw-r--r--Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs22
3 files changed, 24 insertions, 2 deletions
diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs
index d917918..97b41b5 100644
--- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs
+++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalReader.cs
@@ -569,7 +569,7 @@ namespace Newtonsoft.Json.Serialization
if (property.NullValueHandling.GetValueOrDefault(Serializer.NullValueHandling) == NullValueHandling.Ignore && value == null)
return false;
- if (property.DefaultValueHandling.GetValueOrDefault(Serializer.DefaultValueHandling) == DefaultValueHandling.Ignore && Equals(value, property.DefaultValue))
+ if (property.DefaultValueHandling.GetValueOrDefault(Serializer.DefaultValueHandling) == DefaultValueHandling.Ignore && MiscellaneousUtils.ValueEquals(value, property.DefaultValue))
return false;
if (!property.Writable)
diff --git a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs
index c25e995..2c89c2f 100644
--- a/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs
+++ b/Src/Newtonsoft.Json/Serialization/JsonSerializerInternalWriter.cs
@@ -184,7 +184,7 @@ namespace Newtonsoft.Json.Serialization
return;
if (property.DefaultValueHandling.GetValueOrDefault(Serializer.DefaultValueHandling) ==
- DefaultValueHandling.Ignore && Equals(memberValue, defaultValue))
+ DefaultValueHandling.Ignore && MiscellaneousUtils.ValueEquals(memberValue, defaultValue))
return;
if (ShouldWriteReference(memberValue, property, contract))
diff --git a/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs b/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs
index f0fa2dd..84375eb 100644
--- a/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs
+++ b/Src/Newtonsoft.Json/Utilities/MiscellaneousUtils.cs
@@ -12,6 +12,28 @@ namespace Newtonsoft.Json.Utilities
internal static class MiscellaneousUtils
{
+ public static bool ValueEquals(object objA, object objB)
+ {
+ if (objA == null && objB == null)
+ return true;
+ if (objA != null && objB == null)
+ return false;
+ if (objA == null && objB != null)
+ return false;
+
+ if (objA.GetType() != objB.GetType())
+ {
+ if (ConvertUtils.IsInteger(objA) && ConvertUtils.IsInteger(objB))
+ return Convert.ToDecimal(objA).Equals(Convert.ToDecimal(objB));
+ else if ((objA is double || objA is float || objA is decimal) && (objB is double || objB is float || objB is decimal))
+ return MathUtils.ApproxEquals(Convert.ToDouble(objA), Convert.ToDouble(objB));
+ else
+ return false;
+ }
+
+ return objA.Equals(objB);
+ }
+
public static ArgumentOutOfRangeException CreateArgumentOutOfRangeException(string paramName, object actualValue, string message)
{
string newMessage = message + Environment.NewLine + @"Actual value was {0}.".FormatWith(CultureInfo.InvariantCulture, actualValue);