diff --git a/Doc/ReducingSerializedJSONSize.aml b/Doc/ReducingSerializedJSONSize.aml
index 7a996448..247c98ac 100644
--- a/Doc/ReducingSerializedJSONSize.aml
+++ b/Doc/ReducingSerializedJSONSize.aml
@@ -39,7 +39,7 @@
The way to tackle this scenario is to add the
T:System.Runtime.Serialization.DataContractAttribute
to the class and
- T:System.Runtime.Serialization.DataMemberAttributes
+ T:System.Runtime.Serialization.DataMemberAttribute
to the properties to serialize. This is opt-in
serialization, only the properties you mark up with be serialized, compared to
opt-out serialization using JsonIgnoreAttribute.
diff --git a/Src/Newtonsoft.Json.Tests/Converters/JsonValueConverterTests.cs b/Src/Newtonsoft.Json.Tests/Converters/JsonValueConverterTests.cs
index fbda802a..b17c6926 100644
--- a/Src/Newtonsoft.Json.Tests/Converters/JsonValueConverterTests.cs
+++ b/Src/Newtonsoft.Json.Tests/Converters/JsonValueConverterTests.cs
@@ -232,6 +232,39 @@ namespace Newtonsoft.Json.Tests.Converters
]", json);
}
+ [Test]
+ public void SerializeDouble()
+ {
+ JsonObject o = new JsonObject();
+ o["zero"] = JsonValue.CreateNumberValue(0);
+ o["int"] = JsonValue.CreateNumberValue(1);
+ o["smallfraction"] = JsonValue.CreateNumberValue(3.0000000000000009);
+ o["double"] = JsonValue.CreateNumberValue(1.1);
+ o["probablyint"] = JsonValue.CreateNumberValue(1.0);
+ o["Epsilon"] = JsonValue.CreateNumberValue(double.Epsilon);
+ o["MinValue"] = JsonValue.CreateNumberValue(double.MinValue);
+ o["MaxValue"] = JsonValue.CreateNumberValue(double.MaxValue);
+ o["NaN"] = JsonValue.CreateNumberValue(double.NaN);
+ o["NegativeInfinity"] = JsonValue.CreateNumberValue(double.NegativeInfinity);
+ o["PositiveInfinity"] = JsonValue.CreateNumberValue(double.PositiveInfinity);
+
+ string json = JsonConvert.SerializeObject(o, Formatting.Indented);
+
+ Assert.AreEqual(@"{
+ ""PositiveInfinity"": Infinity,
+ ""NegativeInfinity"": -Infinity,
+ ""MinValue"": -1.7976931348623157E+308,
+ ""double"": 1.1,
+ ""int"": 1,
+ ""zero"": 0,
+ ""Epsilon"": 4.94065645841247E-324,
+ ""MaxValue"": 1.7976931348623157E+308,
+ ""NaN"": NaN,
+ ""smallfraction"": 3.0000000000000009,
+ ""probablyint"": 1
+}", json);
+ }
+
//[Test]
public void DeserializePerformance()
{
diff --git a/Src/Newtonsoft.Json/Converters/JsonValueConverter.cs b/Src/Newtonsoft.Json/Converters/JsonValueConverter.cs
index 20c4be87..c59f59e7 100644
--- a/Src/Newtonsoft.Json/Converters/JsonValueConverter.cs
+++ b/Src/Newtonsoft.Json/Converters/JsonValueConverter.cs
@@ -66,7 +66,14 @@ namespace Newtonsoft.Json.Converters
break;
case JsonValueType.Number:
{
- writer.WriteValue(value.GetNumber());
+ // JsonValue doesn't support integers
+ // serialize whole numbers without a decimal point
+ double d = value.GetNumber();
+ bool isInteger = (d % 1 == 0);
+ if (isInteger && d <= long.MaxValue && d >= long.MinValue)
+ writer.WriteValue(Convert.ToInt64(d));
+ else
+ writer.WriteValue(d);
}
break;
case JsonValueType.Object: