From f42cc2a8c38b8da7fc9a28a5de09b386973fc69f Mon Sep 17 00:00:00 2001 From: Christine Poerschke Date: Fri, 18 Nov 2016 15:57:35 +0000 Subject: [PATCH] SOLR-9782: for json.nl expand test coverage and comments w.r.t. NamedList(null=null) --- .../apache/solr/response/JSONResponseWriter.java | 14 +++++++------- .../org/apache/solr/response/JSONWriterTest.java | 11 ++++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java b/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java index 462c6561870..ae1ea4703ad 100644 --- a/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java +++ b/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java @@ -188,10 +188,10 @@ class JSONWriter extends TextResponseWriter { } /** Represents a NamedList directly as a JSON Object (essentially a Map) - * repeating any keys if they are repeated in the NamedList. null is mapped - * to "". + * repeating any keys if they are repeated in the NamedList. + * null key is mapped to "". */ - // NamedList("a"=1,"bar"="foo",null=3) => {"a":1,"bar":"foo","":3} + // NamedList("a"=1,"bar"="foo",null=3,null=null) => {"a":1,"bar":"foo","":3,"":null} protected void writeNamedListAsMapWithDups(String name, NamedList val) throws IOException { int sz = val.size(); writeMapOpener(sz); @@ -214,7 +214,7 @@ class JSONWriter extends TextResponseWriter { } // Represents a NamedList directly as an array of JSON objects... - // NamedList("a"=1,"b"=2,null=3) => [{"a":1},{"b":2},3] + // NamedList("a"=1,"b"=2,null=3,null=null) => [{"a":1},{"b":2},3,null] protected void writeNamedListAsArrMap(String name, NamedList val) throws IOException { int sz = val.size(); indent(); @@ -249,7 +249,7 @@ class JSONWriter extends TextResponseWriter { } // Represents a NamedList directly as an array of JSON objects... - // NamedList("a"=1,"b"=2,null=3) => [["a",1],["b",2],[null,3]] + // NamedList("a"=1,"b"=2,null=3,null=null) => [["a",1],["b",2],[null,3],[null,null]] protected void writeNamedListAsArrArr(String name, NamedList val) throws IOException { int sz = val.size(); indent(); @@ -293,7 +293,7 @@ class JSONWriter extends TextResponseWriter { // Represents a NamedList directly as an array with keys/values // interleaved. - // NamedList("a"=1,"b"=2,null=3) => ["a",1,"b",2,null,3] + // NamedList("a"=1,"b"=2,null=3,null=null) => ["a",1,"b",2,null,3,null,null] protected void writeNamedListAsFlat(String name, NamedList val) throws IOException { int sz = val.size(); writeArrayOpener(sz*2); @@ -676,7 +676,7 @@ class JSONWriter extends TextResponseWriter { /** * Writes NamedLists directly as an array of NamedValuePair JSON objects... - * NamedList("a"=1,"b"=2,null=3) => [{"name":"a","int":1},{"name":"b","int":2},{"int":3}] + * NamedList("a"=1,"b"=2,null=3,null=null) => [{"name":"a","int":1},{"name":"b","int":2},{"int":3},{"null":null}] * NamedList("a"=1,"bar"="foo",null=3.4f) => [{"name":"a","int":1},{"name":"bar","str":"foo"},{"float":3.4}] */ class ArrayOfNamedValuePairJSONWriter extends JSONWriter { diff --git a/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java b/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java index 076d322437f..a056016d5b8 100644 --- a/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java +++ b/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java @@ -98,6 +98,7 @@ public class JSONWriterTest extends SolrTestCaseJ4 { NamedList nl = new NamedList(); nl.add("data1", "he\u2028llo\u2029!"); // make sure that 2028 and 2029 are both escaped (they are illegal in javascript) nl.add(null, 42); + nl.add(null, null); rsp.add("nl", nl); rsp.add("byte", Byte.valueOf((byte)-3)); @@ -108,15 +109,15 @@ public class JSONWriterTest extends SolrTestCaseJ4 { final String expectedNLjson; if (namedListStyle == JSONWriter.JSON_NL_FLAT) { - expectedNLjson = "\"nl\":[\"data1\",\"he\\u2028llo\\u2029!\",null,42]"; + expectedNLjson = "\"nl\":[\"data1\",\"he\\u2028llo\\u2029!\",null,42,null,null]"; } else if (namedListStyle == JSONWriter.JSON_NL_MAP) { - expectedNLjson = "\"nl\":{\"data1\":\"he\\u2028llo\\u2029!\",\"\":42}"; + expectedNLjson = "\"nl\":{\"data1\":\"he\\u2028llo\\u2029!\",\"\":42,\"\":null}"; } else if (namedListStyle == JSONWriter.JSON_NL_ARROFARR) { - expectedNLjson = "\"nl\":[[\"data1\",\"he\\u2028llo\\u2029!\"],[null,42]]"; + expectedNLjson = "\"nl\":[[\"data1\",\"he\\u2028llo\\u2029!\"],[null,42],[null,null]]"; } else if (namedListStyle == JSONWriter.JSON_NL_ARROFMAP) { - expectedNLjson = "\"nl\":[{\"data1\":\"he\\u2028llo\\u2029!\"},42]"; + expectedNLjson = "\"nl\":[{\"data1\":\"he\\u2028llo\\u2029!\"},42,null]"; } else if (namedListStyle == JSONWriter.JSON_NL_ARROFNVP) { - expectedNLjson = "\"nl\":[{\"name\":\"data1\",\"str\":\"he\\u2028llo\\u2029!\"},{\"int\":42}]"; + expectedNLjson = "\"nl\":[{\"name\":\"data1\",\"str\":\"he\\u2028llo\\u2029!\"},{\"int\":42},{\"null\":null}]"; } else { expectedNLjson = null; fail("unexpected namedListStyle="+namedListStyle);