use of com.jayway.jsonpath.JsonPath in project qpp-conversion-tool by CMSgov.
the class PathCorrelator method prepPath.
/**
* Assemble an xpath using the given json path and json wrapper.
*
* @param jsonPath definite json path
* @param wrapper object representation of QPP json
* @return xpath that correlates to supplied json path
*/
public static String prepPath(String jsonPath, JsonWrapper wrapper) {
String base = "$";
String leaf = jsonPath;
int lastIndex = jsonPath.lastIndexOf('.');
JsonWrapper metaWrapper = new JsonWrapper(wrapper, false);
if (lastIndex > 0) {
base = jsonPath.substring(0, lastIndex);
leaf = jsonPath.substring(lastIndex + 1);
}
JsonPath compiledPath = JsonPath.compile(base);
Map<String, Object> jsonMap = compiledPath.read(metaWrapper.toString());
Map<String, String> metaMap = getMetaMap(jsonMap, leaf);
String preparedPath = "";
if (metaMap != null) {
preparedPath = makePath(metaMap, leaf);
}
return preparedPath;
}
use of com.jayway.jsonpath.JsonPath in project JsonPath by jayway.
the class ApiResource method validate.
@GET
@Path("/validate")
@Produces(MediaType.APPLICATION_JSON)
public Response validate(@QueryParam("path") String path) {
int result = -1;
try {
JsonPath compiled = JsonPath.compile(path);
result = compiled.isDefinite() ? 0 : 1;
} catch (Exception e) {
}
return Response.ok(Collections.singletonMap("result", result)).build();
}
use of com.jayway.jsonpath.JsonPath in project JsonPath by jayway.
the class IssuesTest method github_89.
@Test(expected = PathNotFoundException.class)
public void github_89() {
com.google.gson.JsonObject json = new JsonObject();
json.addProperty("foo", "bar");
JsonPath path = JsonPath.compile("$.foo");
String object = path.read(json);
}
use of com.jayway.jsonpath.JsonPath in project JsonPath by jayway.
the class IssuesTest method issue_94_2.
@Test
public void issue_94_2() throws Exception {
LRUCache cache = new LRUCache(5);
JsonPath dummy = JsonPath.compile("$");
cache.put("1", dummy);
cache.put("2", dummy);
cache.put("3", dummy);
cache.put("4", dummy);
cache.put("5", dummy);
cache.put("6", dummy);
cache.get("1");
cache.get("2");
cache.get("3");
cache.get("4");
cache.get("5");
cache.get("6");
cache.get("2");
cache.get("3");
cache.get("4");
cache.get("5");
cache.get("6");
cache.get("3");
cache.get("4");
cache.get("5");
cache.get("6");
cache.get("4");
cache.get("5");
cache.get("6");
cache.get("5");
cache.get("6");
cache.get("6");
assertThat(cache.getSilent("6")).isNotNull();
assertThat(cache.getSilent("5")).isNotNull();
assertThat(cache.getSilent("4")).isNotNull();
assertThat(cache.getSilent("3")).isNotNull();
assertThat(cache.getSilent("2")).isNotNull();
assertThat(cache.getSilent("1")).isNull();
}
use of com.jayway.jsonpath.JsonPath in project graylog2-server by Graylog2.
the class HTTPJSONPathDataAdapterTest method parseEmptyBody.
@Test
public void parseEmptyBody() throws Exception {
final JsonPath singlePath = JsonPath.compile("$.hello");
final JsonPath multiPath = JsonPath.compile("$.list");
final LookupResult result = HTTPJSONPathDataAdapter.parseBody(singlePath, multiPath, emptyBody);
assertThat(result).isNull();
}
Aggregations