Skip to content

Commit

Permalink
SOLR-17009 json.wrf parameter ignored in JacksonJsonWriter (#1977)
Browse files Browse the repository at this point in the history
  • Loading branch information
stillalex authored Oct 4, 2023
1 parent 74ad7bb commit 540f61c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions solr/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ public WriterImpl(

@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();
}

Expand Down
32 changes: 32 additions & 0 deletions solr/core/src/test/org/apache/solr/response/JSONWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -314,4 +315,35 @@ public void testConstantsUnchanged() {
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();
}
}

0 comments on commit 540f61c

Please sign in to comment.