use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestBulkSchemaAPI method testAddIllegalDynamicField.
public void testAddIllegalDynamicField() throws Exception {
RestTestHarness harness = restTestHarness;
String newFieldName = "illegal";
String payload = "{\n" + " 'add-dynamic-field' : {\n" + " 'name':'" + newFieldName + "',\n" + " 'type':'string',\n" + " 'stored':true,\n" + " 'indexed':true\n" + " }\n" + " }";
String response = harness.post("/schema?wt=json", json(payload));
Map map = (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
assertNotNull(response, map.get("errors"));
map = getObj(harness, newFieldName, "dynamicFields");
assertNull(newFieldName + " illegal dynamic field should not have been added to schema", map);
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class RequestUtil method getParamsFromJSON.
private static void getParamsFromJSON(Map<String, String[]> params, String json) {
if (json.indexOf("params") < 0) {
return;
}
JSONParser parser = new JSONParser(json);
try {
JSONUtil.expect(parser, JSONParser.OBJECT_START);
boolean found = JSONUtil.advanceToMapKey(parser, "params", false);
if (!found) {
return;
}
// advance to the value
parser.nextEvent();
Object o = ObjectBuilder.getVal(parser);
if (!(o instanceof Map))
return;
Map<String, Object> map = (Map<String, Object>) o;
// Solr params are based on String though, so we need to convert
for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey();
Object val = entry.getValue();
if (params.get(key) != null) {
continue;
}
if (val == null) {
params.remove(key);
} else if (val instanceof List) {
List lst = (List) val;
String[] vals = new String[lst.size()];
for (int i = 0; i < vals.length; i++) {
vals[i] = lst.get(i).toString();
}
params.put(key, vals);
} else {
params.put(key, new String[] { val.toString() });
}
}
} catch (Exception e) {
// ignore parse exceptions at this stage, they may be caused by incomplete macro expansions
return;
}
}
Aggregations