
com.jayway.jsonpath.web.bench.Bench Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of json-path-web-test Show documentation
Show all versions of json-path-web-test Show documentation
A library to query and verify JSON
package com.jayway.jsonpath.web.bench;
import com.jayway.jsonpath.Configuration;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.Option;
import com.jayway.jsonpath.internal.spi.json.JacksonJsonProvider;
import io.gatling.jsonpath.JsonPath$;
import org.boon.json.JsonParser;
import org.boon.json.ObjectMapper;
import org.boon.json.implementation.JsonParserCharArray;
import org.boon.json.implementation.ObjectMapperImpl;
import scala.collection.Iterator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Bench {
protected final String json;
protected final String path;
private final boolean optionAsValues;
private final boolean flagWrap;
private final boolean flagSuppress;
private final boolean flagNullLeaf;
private final boolean flagRequireProps;
public Bench(String json, String path, boolean optionAsValues, boolean flagWrap, boolean flagSuppress, boolean flagNullLeaf, boolean flagRequireProps) {
this.json = json;
this.path = path;
this.optionAsValues = optionAsValues;
this.flagWrap = flagWrap;
this.flagSuppress = flagSuppress;
this.flagNullLeaf = flagNullLeaf;
this.flagRequireProps = flagRequireProps;
}
public Result runJayway() {
String result = null;
String error = null;
long time;
Object res = null;
Configuration configuration = Configuration.defaultConfiguration();
if(flagWrap){
configuration = configuration.addOptions(Option.ALWAYS_RETURN_LIST);
}
if(flagSuppress){
configuration = configuration.addOptions(Option.SUPPRESS_EXCEPTIONS);
}
if (!optionAsValues) {
configuration = configuration.addOptions(Option.AS_PATH_LIST);
}
if(flagNullLeaf){
configuration = configuration.addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL);
}
if(flagRequireProps){
configuration = configuration.addOptions(Option.REQUIRE_PROPERTIES);
}
long now = System.currentTimeMillis();
try {
res = JsonPath.using(configuration).parse(json).read(path);
} catch (Exception e) {
error = getError(e);
} finally {
time = System.currentTimeMillis() - now;
if (res instanceof String) {
result = "\"" + res + "\"";
} else if (res instanceof Number) {
result = res.toString();
} else if (res instanceof Boolean) {
result = res.toString();
} else {
result = res != null ? Configuration.defaultConfiguration().jsonProvider().toJson(res) : "null";
}
return new Result("jayway", time, result, error);
}
}
public Result runBoon() {
String result = null;
String error = null;
long time;
Iterator
© 2015 - 2025 Weber Informatics LLC | Privacy Policy