From 3c88523556087787028243cacd957faf700bfe0a Mon Sep 17 00:00:00 2001 From: JamesNK Date: Thu, 28 Feb 2008 09:53:20 +0000 Subject: [PATCH] Change: JsonSerializer will serialize null rather than throwing an exception. --- Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs | 14 ++++++++++++++ Src/Newtonsoft.Json/JsonSerializer.cs | 3 --- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs b/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs index a8ef48b3..423b7257 100644 --- a/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonSerializerTest.cs @@ -761,5 +761,19 @@ keyword such as type of business."" Store s4 = (Store)jsonSerializer.Deserialize(new JsonReader(new StringReader(@"{""Color"":2,""Establised"":""\/Date(1264071600000+1300)\/"",""Width"":1.1,""Employees"":999,""RoomsPerFloor"":[1,2,3,4,5,6,7,8,9],""Open"":false,""Symbol"":""@"",""Mottos"":[""Hello World"",""öäüÖÄÜ\\'{new Date(12345);}[222]_µ@²³~"",null,"" ""],""Cost"":100980.1,""Escape"":""\r\n\t\f\b?{\\r\\n\""'"",""product"":[{""Name"":""Rocket"",""Expiry"":""\/Date(949485690000+1300)\/"",""Price"":0},{""Name"":""Alien"",""Expiry"":""\/Date(946638000000)\/"",""Price"":0}]}")), typeof(Store)); Assert.AreEqual(s1.Establised, s3.Establised); } + + [Test] + public void SerializeObject() + { + string json = JavaScriptConvert.SerializeObject(new object()); + Assert.AreEqual("{}", json); + } + + [Test] + public void SerializeNull() + { + string json = JavaScriptConvert.SerializeObject(null); + Assert.AreEqual("null", json); + } } } \ No newline at end of file diff --git a/Src/Newtonsoft.Json/JsonSerializer.cs b/Src/Newtonsoft.Json/JsonSerializer.cs index 359ed715..1f9d1932 100644 --- a/Src/Newtonsoft.Json/JsonSerializer.cs +++ b/Src/Newtonsoft.Json/JsonSerializer.cs @@ -531,9 +531,6 @@ namespace Newtonsoft.Json if (jsonWriter == null) throw new ArgumentNullException("jsonWriter"); - if (value == null) - throw new ArgumentNullException("value"); - SerializeValue(jsonWriter, value); }