diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 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 Fixes 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 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.java index 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); + } + }