use of org.noggit.JSONParser in project lucene-solr by apache.
the class TestJsonFacetRefinement method fromJSON.
/** Use SimpleOrderedMap rather than Map to match responses from shards */
public static Object fromJSON(String json) throws IOException {
JSONParser parser = new JSONParser(json);
ObjectBuilder ob = new ObjectBuilder(parser) {
@Override
public Object newObject() throws IOException {
return new SimpleOrderedMap();
}
@Override
public void addKeyVal(Object map, Object key, Object val) throws IOException {
((SimpleOrderedMap) map).add(key.toString(), val);
}
};
return ob.getObject();
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class CollectionTester method match.
/**
* @param path JSON path expression
* @param input JSON Structure to parse and test against
* @param expected expected value of path
* @param delta tollerance allowed in comparing float/double values
*/
public static String match(String path, String input, String expected, double delta) throws Exception {
Object inputObj = failRepeatedKeys ? new NoDupsObjectBuilder(new JSONParser(input)).getVal() : ObjectBuilder.fromJSON(input);
Object expectObj = failRepeatedKeys ? new NoDupsObjectBuilder(new JSONParser(expected)).getVal() : ObjectBuilder.fromJSON(expected);
return matchObj(path, inputObj, expectObj, delta);
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class CollectionTester method matchObj.
/**
* @param input Object structure to parse and test against
* @param pathAndExpected JSON path expression + '==' + expected value
* @param delta tollerance allowed in comparing float/double values
*/
public static String matchObj(Object input, String pathAndExpected, double delta) throws Exception {
int pos = pathAndExpected.indexOf("==");
String path = pos >= 0 ? pathAndExpected.substring(0, pos) : null;
String expected = pos >= 0 ? pathAndExpected.substring(pos + 2) : pathAndExpected;
Object expectObj = failRepeatedKeys ? new NoDupsObjectBuilder(new JSONParser(expected)).getVal() : ObjectBuilder.fromJSON(expected);
return matchObj(path, input, expectObj, delta);
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class SolrCloudExampleTest method getAsMap.
private Map getAsMap(CloudSolrClient cloudClient, String uri) throws Exception {
HttpGet get = new HttpGet(uri);
HttpEntity entity = null;
try {
entity = cloudClient.getLbClient().getHttpClient().execute(get).getEntity();
String response = EntityUtils.toString(entity, StandardCharsets.UTF_8);
return (Map) ObjectBuilder.getVal(new JSONParser(new StringReader(response)));
} finally {
EntityUtils.consumeQuietly(entity);
}
}
use of org.noggit.JSONParser in project lucene-solr by apache.
the class CommandOperation method parse.
/**
* Parse the command operations into command objects
*/
public static List<CommandOperation> parse(Reader rdr) throws IOException {
JSONParser parser = new JSONParser(rdr);
parser.setFlags(parser.getFlags() | JSONParser.ALLOW_MISSING_COLON_COMMA_BEFORE_OBJECT | JSONParser.OPTIONAL_OUTER_BRACES);
ObjectBuilder ob = new ObjectBuilder(parser);
if (parser.lastEvent() != JSONParser.OBJECT_START) {
throw new RuntimeException("The JSON must be an Object of the form {\"command\": {...},...");
}
List<CommandOperation> operations = new ArrayList<>();
for (; ; ) {
int ev = parser.nextEvent();
if (ev == JSONParser.OBJECT_END)
return operations;
Object key = ob.getKey();
ev = parser.nextEvent();
Object val = ob.getVal();
if (val instanceof List) {
List list = (List) val;
for (Object o : list) {
if (!(o instanceof Map)) {
operations.add(new CommandOperation(String.valueOf(key), list));
break;
} else {
operations.add(new CommandOperation(String.valueOf(key), o));
}
}
} else {
operations.add(new CommandOperation(String.valueOf(key), val));
}
}
}
Aggregations