Browse Source

Missing again

pull/1/head
David Baldwin 14 years ago
parent
commit
b91c61be0f
  1. 35
      json-path/src/main/java/com/jayway/jsonpath/JsonPath.java

35
json-path/src/main/java/com/jayway/jsonpath/JsonPath.java

@ -134,10 +134,36 @@ public class JsonPath {
public JsonElement read(JsonElement json) throws JsonException {
FilterOutput filterOutput = filters.filter(json);
return filterOutput.getResultAsJson();
if (filterOutput == null || filterOutput.getResult() == null) {
throw new JsonException("Element not found");
}
return filterOutput.getResult();
}
/**
* Applies this json path to the provided object
*
* @param json a json Object
* @param <T>
* @return list of objects matched by the given path
* @throws JsonException
*/
public List<JsonElement> readResultSet(JsonElement json) throws JsonException {
FilterOutput filterOutput = filters.filter(json);
if (filterOutput == null || filterOutput.getResult() == null) {
throw new JsonException("Element not found");
}
return filterOutput.getList();
}
/**
* Applies this json path to the provided object
*
@ -187,6 +213,13 @@ public class JsonPath {
}
public static List<JsonElement> readResultSet(JsonElement json, String jsonPath) throws JsonException {
return compile(jsonPath).readResultSet(json);
}
public static JsonElement parse(String json) {
try {
return JsonFactory.getInstance().parse(json);

Loading…
Cancel
Save