From b91c61be0f97e7d6b842037d4e3c7bcf7474699f Mon Sep 17 00:00:00 2001 From: David Baldwin Date: Fri, 29 Jul 2011 12:28:40 -0700 Subject: [PATCH] Missing again --- .../java/com/jayway/jsonpath/JsonPath.java | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java index 8dff12ee..8b8a3b5e 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java +++ b/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java @@ -133,10 +133,36 @@ public class JsonPath { */ public JsonElement read(JsonElement json) throws JsonException { 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 + * @return list of objects matched by the given path + * @throws JsonException + */ + public List 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 @@ -186,6 +212,13 @@ public class JsonPath { return compile(jsonPath).read(json); } + + public static List readResultSet(JsonElement json, String jsonPath) throws JsonException { + return compile(jsonPath).readResultSet(json); + } + + + public static JsonElement parse(String json) { try {