mirror of https://github.com/apache/lucene.git
SOLR-9709: add json.nl=map example comment, expand json.nl test coverage.
This commit is contained in:
parent
92f56ea9dd
commit
d0e32f3e5c
|
@ -82,11 +82,14 @@ class JSONWriter extends TextResponseWriter {
|
|||
final protected String namedListStyle;
|
||||
|
||||
static final String JSON_NL_STYLE="json.nl";
|
||||
static final int JSON_NL_STYLE_COUNT = 5; // for use by JSONWriterTest
|
||||
|
||||
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_NL_ARROFNVP="arrnvp";
|
||||
|
||||
static final String JSON_WRAPPER_FUNCTION="json.wrf";
|
||||
|
||||
public JSONWriter(Writer writer, SolrQueryRequest req, SolrQueryResponse rsp) {
|
||||
|
@ -181,6 +184,7 @@ class JSONWriter extends TextResponseWriter {
|
|||
* repeating any keys if they are repeated in the NamedList. null is mapped
|
||||
* to "".
|
||||
*/
|
||||
// NamedList("a"=1,"bar"="foo",null=3) => {"a":1,"bar":"foo","":3}
|
||||
protected void writeNamedListAsMapWithDups(String name, NamedList val) throws IOException {
|
||||
int sz = val.size();
|
||||
writeMapOpener(sz);
|
||||
|
|
|
@ -76,7 +76,20 @@ public class JSONWriterTest extends SolrTestCaseJ4 {
|
|||
|
||||
@Test
|
||||
public void testJSON() throws IOException {
|
||||
final String namedListStyle = (random().nextBoolean() ? JSONWriter.JSON_NL_ARROFARR : JSONWriter.JSON_NL_ARROFNVP);
|
||||
final String[] namedListStyles = new String[] {
|
||||
JSONWriter.JSON_NL_FLAT,
|
||||
JSONWriter.JSON_NL_MAP,
|
||||
JSONWriter.JSON_NL_ARROFARR,
|
||||
JSONWriter.JSON_NL_ARROFMAP,
|
||||
JSONWriter.JSON_NL_ARROFNVP,
|
||||
};
|
||||
for (final String namedListStyle : namedListStyles) {
|
||||
implTestJSON(namedListStyle);
|
||||
}
|
||||
assertEquals(JSONWriter.JSON_NL_STYLE_COUNT, namedListStyles.length);
|
||||
}
|
||||
|
||||
private void implTestJSON(final String namedListStyle) throws IOException {
|
||||
SolrQueryRequest req = req("wt","json","json.nl",namedListStyle);
|
||||
SolrQueryResponse rsp = new SolrQueryResponse();
|
||||
JSONResponseWriter w = new JSONResponseWriter();
|
||||
|
@ -94,8 +107,14 @@ public class JSONWriterTest extends SolrTestCaseJ4 {
|
|||
w.write(buf, req, rsp);
|
||||
|
||||
final String expectedNLjson;
|
||||
if (namedListStyle == JSONWriter.JSON_NL_ARROFARR) {
|
||||
if (namedListStyle == JSONWriter.JSON_NL_FLAT) {
|
||||
expectedNLjson = "\"nl\":[\"data1\",\"he\\u2028llo\\u2029!\",null,42]";
|
||||
} else if (namedListStyle == JSONWriter.JSON_NL_MAP) {
|
||||
expectedNLjson = "\"nl\":{\"data1\":\"he\\u2028llo\\u2029!\",\"\":42}";
|
||||
} else if (namedListStyle == JSONWriter.JSON_NL_ARROFARR) {
|
||||
expectedNLjson = "\"nl\":[[\"data1\",\"he\\u2028llo\\u2029!\"],[null,42]]";
|
||||
} else if (namedListStyle == JSONWriter.JSON_NL_ARROFMAP) {
|
||||
expectedNLjson = "\"nl\":[{\"data1\":\"he\\u2028llo\\u2029!\"},42]";
|
||||
} else if (namedListStyle == JSONWriter.JSON_NL_ARROFNVP) {
|
||||
expectedNLjson = "\"nl\":[{\"name\":\"data1\",\"str\":\"he\\u2028llo\\u2029!\"},{\"int\":42}]";
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue