Apache Lucene open-source search software
SOLR-9551: Add JSONWriter constructor variant, JSONWriterTest.testConstantsUnchanged test. (Jonny Marks, Christine Poerschke)
Christine Poerschkeef5da9705d99
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 662f6dd6944..242052a88b6 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -180,6 +180,9 @@ Other Changes* SOLR-6090: Remove unreachable printLayout usage in cloud tests. (Cao Manh Dat via shalin)+* SOLR-9551: Add JSONWriter constructor variant, JSONWriterTest.testConstantsUnchanged test.+ (Jonny Marks, Christine Poerschke)+================== 6.2.1 ==================Bug Fixesdiff --git a/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java b/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.javaindex cd8d07c6d8c..522030fbe0f 100644--- a/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java+++ b/solr/core/src/java/org/apache/solr/response/JSONResponseWriter.java@@ -66,19 +66,26 @@ public class JSONResponseWriter implements QueryResponseWriter {class JSONWriter extends TextResponseWriter {protected String wrapperFunction;- private String namedListStyle;+ final private String namedListStyle;- private static final String JSON_NL_STYLE="json.nl";- private static final String JSON_NL_MAP="map";- private static final String JSON_NL_FLAT="flat";- private static final String JSON_NL_ARROFARR="arrarr";- private static final String JSON_NL_ARROFMAP="arrmap";- private static final String JSON_WRAPPER_FUNCTION="json.wrf";+ static final String JSON_NL_STYLE="json.nl";+ static final String JSON_NL_MAP="map";+ static final String JSON_NL_FLAT="flat";+ static final String JSON_NL_ARROFARR="arrarr";+ static final String JSON_NL_ARROFMAP="arrmap";+ static final String JSON_WRAPPER_FUNCTION="json.wrf";public JSONWriter(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) {+ this(writer, req, rsp,+ req.getParams().get(JSON_WRAPPER_FUNCTION),+ req.getParams().get(JSON_NL_STYLE, JSON_NL_FLAT).intern());+ }++ public JSONWriter(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp,+ String wrapperFunction, String namedListStyle) {super(writer, req, rsp);- namedListStyle = req.getParams().get(JSON_NL_STYLE, JSON_NL_FLAT).intern();- wrapperFunction = req.getParams().get(JSON_WRAPPER_FUNCTION);+ this.wrapperFunction = wrapperFunction;+ this.namedListStyle = namedListStyle;}public void writeResponse() throws IOException {diff --git a/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java b/solr/core/src/test/org/apache/solr/response/JSONWriterTest.javaindex 59de096f3c1..ad390cbb776 100644--- a/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java+++ b/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java@@ -131,4 +131,14 @@ public class JSONWriterTest extends SolrTestCaseJ4 {req.close();}+ @Test+ public void testConstantsUnchanged() {+ assertEquals("json.nl", JSONWriter.JSON_NL_STYLE);+ assertEquals("map", JSONWriter.JSON_NL_MAP);+ assertEquals("flat", JSONWriter.JSON_NL_FLAT);+ assertEquals("arrarr", JSONWriter.JSON_NL_ARROFARR);+ assertEquals("arrmap", JSONWriter.JSON_NL_ARROFMAP);+ assertEquals("json.wrf", JSONWriter.JSON_WRAPPER_FUNCTION);+ }+}