use of com.jayway.jsonpath.Configuration in project JsonPath by jayway.
the class Bench method runJayway.
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);
}
}
use of com.jayway.jsonpath.Configuration in project JsonPath by jayway.
the class IssuesTest method issue_22c.
@Test
public void issue_22c() throws Exception {
//Configuration configuration = Configuration.builder().build();
Configuration configuration = Configuration.builder().options(Option.SUPPRESS_EXCEPTIONS).build();
String json = "{\"a\":{\"b\":1,\"c\":2}}";
assertNull(JsonPath.parse(json, configuration).read("a.d"));
}
use of com.jayway.jsonpath.Configuration in project JsonPath by jayway.
the class IssuesTest method issue_22.
@Test(expected = PathNotFoundException.class)
public void issue_22() throws Exception {
Configuration configuration = Configuration.defaultConfiguration();
String json = "{\"a\":{\"b\":1,\"c\":2}}";
JsonPath.parse(json, configuration).read("a.d");
}
use of com.jayway.jsonpath.Configuration in project JsonPath by jayway.
the class IssuesTest method issue_143.
@Test
public void issue_143() {
String json = "{ \"foo\": { \"bar\" : \"val\" }, \"moo\": { \"cow\" : \"val\" } }";
Configuration configuration = Configuration.builder().options(Option.AS_PATH_LIST).build();
List<String> pathList = JsonPath.using(configuration).parse(json).read(JsonPath.compile("$.*.bar"));
assertThat(pathList).containsExactly("$['foo']['bar']");
}
use of com.jayway.jsonpath.Configuration in project JsonPath by jayway.
the class NullHandlingTest method last_token_defaults_to_null.
@Test
public void last_token_defaults_to_null() {
Configuration configuration = Configuration.builder().options(Option.DEFAULT_PATH_LEAF_TO_NULL).build();
assertNull(JsonPath.parse(DOCUMENT, configuration).read("$.children[2].age"));
}
Aggregations