diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java b/json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java index 9e7b9cc2..c896ed9b 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java @@ -147,7 +147,7 @@ public class JsonReader implements ParseContext, DocumentContext { return read(jsonPath); }else { jsonPath = compile(path, filters); - cache.put(path, jsonPath); + cache.put(cacheKey, jsonPath); return read(jsonPath); } diff --git a/json-path/src/test/java/com/jayway/jsonpath/internal/JsonReaderTest.java b/json-path/src/test/java/com/jayway/jsonpath/internal/JsonReaderTest.java index efecffef..7cac7629 100644 --- a/json-path/src/test/java/com/jayway/jsonpath/internal/JsonReaderTest.java +++ b/json-path/src/test/java/com/jayway/jsonpath/internal/JsonReaderTest.java @@ -9,6 +9,7 @@ import org.junit.Test; import com.jayway.jsonpath.BaseTest; import com.jayway.jsonpath.Criteria; +import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.Filter; import com.jayway.jsonpath.JsonPath; @@ -19,9 +20,11 @@ public class JsonReaderTest extends BaseTest { Filter feq = Filter.filter(Criteria.where("category").eq("reference")); Filter fne = Filter.filter(Criteria.where("category").ne("reference")); + + DocumentContext JsonDoc = JsonPath.parse(JSON_DOCUMENT); - List eq = JsonPath.parse(JSON_DOCUMENT).read("$.store.book[?].category", feq); - List ne = JsonPath.parse(JSON_DOCUMENT).read("$.store.book[?].category", fne); + List eq = JsonDoc.read("$.store.book[?].category", feq); + List ne = JsonDoc.read("$.store.book[?].category", fne); Assertions.assertThat(eq).contains("reference"); Assertions.assertThat(ne).doesNotContain("reference");