use of com.jayway.jsonpath.JsonPath in project JsonPath by json-path.
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 JsonPathTest method read_store_book_1.
@Test
public void read_store_book_1() throws Exception {
JsonPath path = JsonPath.compile("$.store.book[1]");
Map map = path.read(DOCUMENT);
assertEquals("Evelyn Waugh", map.get("author"));
}
use of com.jayway.jsonpath.JsonPath in project JsonPath by jayway.
the class IssuesTest method issue_94_1.
@Test
public void issue_94_1() throws Exception {
LRUCache cache = new LRUCache(200);
JsonPath dummy = JsonPath.compile("$");
for (int i = 0; i < 1000; ++i) {
String key = String.valueOf(i);
cache.get(key);
cache.put(key, dummy);
}
assertThat(cache.size()).isEqualTo(200);
}
use of com.jayway.jsonpath.JsonPath in project JsonPath by jayway.
the class Issue629 method testUncloseParenthesis.
@Test
public void testUncloseParenthesis() throws IOException {
try {
JsonPath jsonPath = JsonPath.compile("$.A.B.C.D(");
fail("accepted jsonpath with unclosed parentheses");
} catch (Exception e) {
assertTrue(e.getMessage().startsWith("Arguments to function:"));
}
}
use of com.jayway.jsonpath.JsonPath in project JsonPath by jayway.
the class JsonContext method pathFromCache.
private JsonPath pathFromCache(String path, Predicate[] filters) {
Cache cache = CacheProvider.getCache();
String cacheKey = filters == null || filters.length == 0 ? path : Utils.concat(path, Arrays.toString(filters));
JsonPath jsonPath = cache.get(cacheKey);
if (jsonPath == null) {
jsonPath = compile(path, filters);
cache.put(cacheKey, jsonPath);
}
return jsonPath;
}
Aggregations