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 JsonAsserterImpl method assertNotDefined.
/**
* {@inheritDoc}
*/
public JsonAsserter assertNotDefined(String path) {
try {
Configuration c = Configuration.defaultConfiguration();
JsonPath.using(c).parse(jsonObject).read(path);
throw new AssertionError(format("Document contains the path <%s> but was expected not to.", path));
} catch (PathNotFoundException e) {
}
return this;
}
use of com.jayway.jsonpath.Configuration in project phoenix by apache.
the class JsonEventSerializer method getPatternData.
private String getPatternData(JSONObject json, String pattern) {
Configuration JSON_ORG_CONFIGURATION = Configuration.builder().mappingProvider(new JsonOrgMappingProvider()).jsonProvider(new JsonOrgJsonProvider()).build();
String value;
try {
Object object = JsonPath.using(JSON_ORG_CONFIGURATION).parse(json).read(pattern);
value = object.toString();
} catch (Exception e) {
value = null;
}
return value;
}
use of com.jayway.jsonpath.Configuration in project geode by apache.
the class UseJacksonForJsonPathRule method saveDefaults.
private void saveDefaults() {
try {
Configuration defaultConfiguration = Configuration.defaultConfiguration();
this.jsonProvider = defaultConfiguration.jsonProvider();
this.mappingProvider = defaultConfiguration.mappingProvider();
this.options = defaultConfiguration.getOptions();
this.hadDefaults = true;
} catch (NoClassDefFoundError ignore) {
this.hadDefaults = false;
}
}
use of com.jayway.jsonpath.Configuration in project JsonPath by jayway.
the class IssuesTest method issue_99.
@Test
public void issue_99() throws Exception {
String json = "{\n" + " \"array1\": [\n" + " {\n" + " \"array2\": []\n" + " },\n" + " {\n" + " \"array2\": [\n" + " {\n" + " \"key\": \"test_key\"\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}";
Configuration configuration = Configuration.defaultConfiguration().addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL);
List<String> keys = JsonPath.using(configuration).parse(json).read("$.array1[*].array2[0].key");
}
Aggregations