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

@ -133,10 +133,36 @@ public class JsonPath {
*/ */
public JsonElement read(JsonElement json) throws JsonException { public JsonElement read(JsonElement json) throws JsonException {
FilterOutput filterOutput = filters.filter(json); FilterOutput filterOutput = filters.filter(json);
if (filterOutput == null || filterOutput.getResult() == null) {
throw new JsonException("Element not found");
}
return filterOutput.getResultAsJson(); 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 * Applies this json path to the provided object
@ -186,6 +212,13 @@ public class JsonPath {
return compile(jsonPath).read(json); return compile(jsonPath).read(json);
} }
public static List<JsonElement> readResultSet(JsonElement json, String jsonPath) throws JsonException {
return compile(jsonPath).readResultSet(json);
}
public static JsonElement parse(String json) { public static JsonElement parse(String json) {
try { try {

Loading…
Cancel
Save