Browse Source

fixed the cache key and the unit test (use the same key when fetching

and looking up cache) #94
pull/137/head
gauravgupta 9 years ago
parent
commit
f25ec6c0cd
  1. 2
      json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java
  2. 7
      json-path/src/test/java/com/jayway/jsonpath/internal/JsonReaderTest.java

2
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);
}

7
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<String> eq = JsonPath.parse(JSON_DOCUMENT).read("$.store.book[?].category", feq);
List<String> ne = JsonPath.parse(JSON_DOCUMENT).read("$.store.book[?].category", fne);
List<String> eq = JsonDoc.read("$.store.book[?].category", feq);
List<String> ne = JsonDoc.read("$.store.book[?].category", fne);
Assertions.assertThat(eq).contains("reference");
Assertions.assertThat(ne).doesNotContain("reference");

Loading…
Cancel
Save