Apache Solr open-source search software
SOLR-17009 json.wrf parameter ignored in JacksonJsonWriter (#1977)
Alex D540f61ce45e5
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex ef7e37ea61e..9a02f787bbe 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -256,6 +256,8 @@ Bug Fixes* SOLR-16644: Fixing the entropy warning threshold using scaling based on poolsize (Raghavan Muthuregunathan)+* SOLR-17009: json.wrf parameter ignored in JacksonJsonWriter (Alex Deparvu)+Dependency Upgrades---------------------diff --git a/solr/core/src/java/org/apache/solr/response/JacksonJsonWriter.java b/solr/core/src/java/org/apache/solr/response/JacksonJsonWriter.javaindex 4de5039ba1e..79b09ae3bf4 100644--- a/solr/core/src/java/org/apache/solr/response/JacksonJsonWriter.java+++ b/solr/core/src/java/org/apache/solr/response/JacksonJsonWriter.java@@ -79,7 +79,13 @@ public class JacksonJsonWriter extends BinaryResponseWriter {@Overridepublic void writeResponse() throws IOException {+ if (wrapperFunction != null) {+ writeStr(null, wrapperFunction + "(", false);+ }super.writeNamedList(null, rsp.getValues());+ if (wrapperFunction != null) {+ writeStr(null, ")", false);+ }gen.close();}diff --git a/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java b/solr/core/src/test/org/apache/solr/response/JSONWriterTest.javaindex 9fcdcea4e5f..7d6e324a418 100644--- a/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java+++ b/solr/core/src/test/org/apache/solr/response/JSONWriterTest.java@@ -16,6 +16,7 @@*/package org.apache.solr.response;+import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.StringWriter;import java.lang.reflect.Method;@@ -314,4 +315,35 @@ public class JSONWriterTest extends SolrTestCaseJ4 {assertEquals("arrntv", JSONWriter.JSON_NL_ARROFNTV);assertEquals("json.wrf", JSONWriter.JSON_WRAPPER_FUNCTION);}++ @Test+ public void testWfrJacksonJsonWriter() throws IOException {+ SolrQueryRequest req = req("wt", "json", JSONWriter.JSON_WRAPPER_FUNCTION, "testFun");+ SolrQueryResponse rsp = new SolrQueryResponse();+ rsp.add("param0", "v0");+ rsp.add("param1", 42);++ JacksonJsonWriter w = new JacksonJsonWriter();+ ByteArrayOutputStream baos = new ByteArrayOutputStream();+ w.write(baos, req, rsp);+ String received = new String(baos.toByteArray(), StandardCharsets.UTF_8);+ String expected = "testFun( {\n \"param0\":\"v0\",\n \"param1\":42\n} )";+ jsonEq(expected, received);+ req.close();+ }++ @Test+ public void testWfrJSONWriter() throws IOException {+ SolrQueryRequest req = req("wt", "json", JSONWriter.JSON_WRAPPER_FUNCTION, "testFun");+ SolrQueryResponse rsp = new SolrQueryResponse();+ rsp.add("param0", "v0");+ rsp.add("param1", 42);++ JSONResponseWriter w = new JSONResponseWriter();+ StringWriter buf = new StringWriter();+ w.write(buf, req, rsp);+ String expected = "testFun({\n \"param0\":\"v0\",\n \"param1\":42})";+ jsonEq(expected, buf.toString());+ req.close();+ }}