Allow passing null to JsonArray.Add()
authorSteffen Kieß <s-kiess@web.de>
Tue, 19 Sep 2017 18:41:16 +0000 (20:41 +0200)
committerMarek Safar <marek.safar@gmail.com>
Mon, 2 Oct 2017 08:39:19 +0000 (10:39 +0200)
null is a valid value in a JSON array, so there is no reason forbid
adding null to the array. JsonArray.Save() already handles null values in
the array.

mcs/class/System.Json/System.Json/JsonArray.cs
mcs/class/System.Json/Test/System.Json/JsonValueTest.cs

index c63004422b5b4919cd665c7adc08144b1aee53e8..524e3e8b75007c0163ca85dce45f1bf4c003b4cb 100644 (file)
@@ -45,9 +45,6 @@ namespace System.Json
 
                public void Add (JsonValue item)
                {
-                       if (item == null)
-                               throw new ArgumentNullException ("item");
-
                        list.Add (item);
                }
 
index b267bd7c98e4e10fef7e93e91cebdf63dedca924..baff3cc32b181579cbcbb199970fde60290d7cb4 100644 (file)
@@ -44,6 +44,9 @@ namespace MonoTests.System
                        Assert.AreEqual (JsonType.Array, j.JsonType, "type");
                        var str = j.ToString ();
                        Assert.AreEqual (str, "[1, 2, 3, null]");
+                       ((JsonArray) j).Add (null);
+                       str = j.ToString ();
+                       Assert.AreEqual (str, "[1, 2, 3, null, null]");
                }
 
                // Test that we correctly serialize JsonObject with null elements.