From: Steffen Kieß Date: Tue, 19 Sep 2017 18:41:16 +0000 (+0200) Subject: Allow passing null to JsonArray.Add() X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=7c6607a000b6239e86d1736a1815264af55c13e2 Allow passing null to JsonArray.Add() 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. --- diff --git a/mcs/class/System.Json/System.Json/JsonArray.cs b/mcs/class/System.Json/System.Json/JsonArray.cs index c63004422b5..524e3e8b750 100644 --- a/mcs/class/System.Json/System.Json/JsonArray.cs +++ b/mcs/class/System.Json/System.Json/JsonArray.cs @@ -45,9 +45,6 @@ namespace System.Json public void Add (JsonValue item) { - if (item == null) - throw new ArgumentNullException ("item"); - list.Add (item); } diff --git a/mcs/class/System.Json/Test/System.Json/JsonValueTest.cs b/mcs/class/System.Json/Test/System.Json/JsonValueTest.cs index b267bd7c98e..baff3cc32b1 100644 --- a/mcs/class/System.Json/Test/System.Json/JsonValueTest.cs +++ b/mcs/class/System.Json/Test/System.Json/JsonValueTest.cs @@ -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.