You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by cp...@apache.org on 2016/11/18 16:41:39 UTC

lucene-solr:branch_6x: SOLR-9782: for json.nl expand test coverage and comments w.r.t. NamedList(null=null)

Repository: lucene-solr
Updated Branches:
  refs/heads/branch_6x 535bf59a3 -> 500f6c787


SOLR-9782: for json.nl expand test coverage and comments w.r.t. NamedList(null=null)


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/500f6c78
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/500f6c78
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/500f6c78

Branch: refs/heads/branch_6x
Commit: 500f6c7875be31c34ca68c58f850b7e64fd049a9
Parents: 535bf59
Author: Christine Poerschke <cp...@apache.org>
Authored: Fri Nov 18 15:57:35 2016 +0000
Committer: Christine Poerschke <cp...@apache.org>
Committed: Fri Nov 18 16:15:18 2016 +0000

----------------------------------------------------------------------
 .../org/apache/solr/response/JSONResponseWriter.java  | 14 +++++++-------
 .../test/org/apache/solr/response/JSONWriterTest.java | 11 ++++++-----
 2 files changed, 13 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/500f6c78/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java
----------------------------------------------------------------------
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 462c656..ae1ea47 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 {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/500f6c78/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java
----------------------------------------------------------------------
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 076d322..a056016 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);