mirror of https://github.com/apache/lucene.git
SOLR-13180: fix classCastEx in JSON Request API
This commit is contained in:
parent
ae72f4f542
commit
7752964e19
|
@ -241,6 +241,8 @@ Bug Fixes
|
|||
* SOLR-13727: Fixed V2Requests - HttpSolrClient replaced first instance of "/solr" with "/api" which
|
||||
caused a change in host names starting with "solr". (Megan Carey via yonik)
|
||||
|
||||
* SOLR-13180: Fix ClassCastException in Json Request API (Johannes Kloos, Jan Høydahl, Munendra S N)
|
||||
|
||||
Other Changes
|
||||
----------------------
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.solr.common.SolrException;
|
||||
|
||||
public class ObjectUtil {
|
||||
|
||||
public static class ConflictHandler {
|
||||
|
@ -103,10 +105,14 @@ public class ObjectUtil {
|
|||
// OK, now we need to merge values
|
||||
handler.handleConflict(outer, path, key, val, existingVal);
|
||||
}
|
||||
} else {
|
||||
} else if (val instanceof Map) {
|
||||
// merging at top level...
|
||||
Map<String,Object> newMap = (Map<String,Object>)val;
|
||||
handler.mergeMap(outer, newMap, path);
|
||||
} else {
|
||||
// todo: find a way to return query param in error message
|
||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,
|
||||
"Expected JSON Object but got " + val.getClass().getSimpleName() + "=" + val);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -270,6 +270,8 @@ public class RequestUtil {
|
|||
ObjectUtil.mergeObjects(json, path, o, handler);
|
||||
}
|
||||
}
|
||||
} catch (JSONParser.ParseException e ) {
|
||||
throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
|
||||
} catch (IOException e) {
|
||||
// impossible
|
||||
}
|
||||
|
|
|
@ -19,12 +19,13 @@ package org.apache.solr.search.json;
|
|||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.solr.JSONTestUtil;
|
||||
import org.apache.solr.SolrTestCaseHS;
|
||||
|
||||
import org.apache.solr.common.SolrException;
|
||||
import org.apache.solr.common.params.CommonParams;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
@LuceneTestCase.SuppressCodecs({"Lucene3x","Lucene40","Lucene41","Lucene42","Lucene45","Appending"})
|
||||
public class TestJsonRequest extends SolrTestCaseHS {
|
||||
|
||||
|
@ -79,6 +80,15 @@ public class TestJsonRequest extends SolrTestCaseHS {
|
|||
, "response/numFound==2"
|
||||
);
|
||||
|
||||
// invalid value
|
||||
SolrException ex = expectThrows(SolrException.class, () -> client.testJQ(params("q", "*:*", "json", "5")));
|
||||
assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, ex.code());
|
||||
|
||||
// this is to verify other json params are not affected
|
||||
client.testJQ( params("q", "cat_s:A", "json.limit", "1"),
|
||||
"response/numFound==2"
|
||||
);
|
||||
|
||||
// test multiple json params
|
||||
client.testJQ( params("json","{query:'cat_s:A'}", "json","{filter:'where_s:NY'}")
|
||||
, "response/numFound==1"
|
||||
|
|
Loading…
Reference in New Issue