This is an automated email from the ASF dual-hosted git repository.

stillalex pushed a commit to branch branch_9_4
in repository https://gitbox.apache.org/repos/asf/solr.git


The following commit(s) were added to refs/heads/branch_9_4 by this push:
     new 7998823498a SOLR-17009 json.wrf parameter ignored in JacksonJsonWriter 
(#1977)
7998823498a is described below

commit 7998823498a29cfd52d5be2703a864e16f4f2000
Author: Alex D <[email protected]>
AuthorDate: Wed Oct 4 08:31:52 2023 -0700

    SOLR-17009 json.wrf parameter ignored in JacksonJsonWriter (#1977)
    
    (cherry picked from commit 540f61ce45e5baf04fef60f4e4fe15e523ef69c6)
---
 solr/CHANGES.txt                                   |  2 ++
 .../apache/solr/response/JacksonJsonWriter.java    |  6 ++++
 .../org/apache/solr/response/JSONWriterTest.java   | 32 ++++++++++++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index b232b06bfaf..c480bee7f35 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -171,6 +171,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
 ---------------------
 * PR#1676: Update org.glassfish.jersey*:* to v2.39.1 (solrbot)
diff --git a/solr/core/src/java/org/apache/solr/response/JacksonJsonWriter.java 
b/solr/core/src/java/org/apache/solr/response/JacksonJsonWriter.java
index 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 {
 
     @Override
     public 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.java
index 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();
+  }
 }

Reply via email to