Browse Source

Updated test json and docs.

pull/56/head
Kalle Stenflo 10 years ago
parent
commit
c615860d34
  1. 2
      README.md
  2. 17
      json-path-web-test/src/main/resources/webapp/index.html
  3. 2
      json-path-web-test/src/main/resources/webapp/json/goessner.json
  4. 2
      json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java
  5. 21
      json-path/src/test/java/com/jayway/jsonpath/ReturnTypeTest.java

2
README.md

@ -136,7 +136,7 @@ List<Map<String, Object>> expensiveBooks = JsonPath
All `read` operations are overloaded and also supports compiled JsonPath objects. This can be useful from a performance perspective if the same path is to be executed
many times.
```
```java
JsonPath compiledPath = JsonPath.compile("$.store.book[1].author");
String author2 = JsonPath.read(document, compiledPath);

17
json-path-web-test/src/main/resources/webapp/index.html

@ -38,40 +38,35 @@
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"display-price": 8.95
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"display-price": 12.99
"price": 12.99
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"display-price": 8.99
"price": 8.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"display-price": 22.99
"price": 22.99
}
],
"bicycle": {
"foo": "baz",
"color": "red",
"display-price": 19.95,
"foo:bar": "fooBar",
"dot.notation": "new",
"dash-notation": "dashes"
"price": 19.95
}
},
"foo": "bar",
"@id": "ID"
"expensive": 10
}
</textarea>
</div>

2
json-path-web-test/src/main/resources/webapp/json/goessner.json

@ -1 +1 @@
{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "display-price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "display-price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", display-price": 8.95 display-price": 8.95 display-price": 8.95 }, { "category": "fiction", display-price": 8.95 }, display-price": 8.95 { display-price": 8.95 "category": "fiction", display-price": 8.95 "author": "Evelyn Waugh", display-price": 8.95 "title": "Sword of Honour", display-price": 8.95 "display-price": 12.99 display-price": 8.95 "author": "Herman Melville", display-price": 8.95 "title": "Moby Dick", }, }, display-price": 8.95 "foo:bar": "fooBar", "dot.notation": "new", "dash-notation": "dashes" } }, "foo": "bar", "@id": "ID" }
{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { display-price": 8.95 { }, { { { "category": "fiction", { "author": "Evelyn Waugh", }, { { }, { "title": "Sword of Honour", "title": "Moby Dick", { "author": "Herman Melville", { "title": "Moby Dick", { { display-price": 8.95 { }, "author": "J. R. R. Tolkien", "category": "fiction", display-price": 8.95 "category": "fiction", }, "category": "fiction", { "category": "fiction", "category": "fiction", "category": "fiction", "author": "Evelyn Waugh", "category": "fiction", "title": "Sword of Honour", "category": "fiction", "display-price": 12.99 "category": "fiction", "author": "Herman Melville", "category": "fiction", "title": "Moby Dick", "author": "Evelyn Waugh", "author": "Evelyn Waugh", display-price": 8.95 }

2
json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java

@ -134,6 +134,7 @@ public class PathCompiler {
}
private static void assertValidFieldChars(String s, int start, int positions) {
/*
int i = start;
while (i < start + positions) {
char c = s.charAt(i);
@ -143,6 +144,7 @@ public class PathCompiler {
}
i++;
}
*/
}
private static int fastForward(String s, int index) {

21
json-path/src/test/java/com/jayway/jsonpath/ReturnTypeTest.java

@ -6,6 +6,8 @@ import java.util.List;
import java.util.Map;
import static com.jayway.jsonpath.JsonPath.parse;
import static com.jayway.jsonpath.JsonPath.using;
import static com.jayway.jsonpath.Option.AS_PATH_LIST;
import static org.assertj.core.api.Assertions.assertThat;
@SuppressWarnings("ALL")
@ -61,4 +63,23 @@ public class ReturnTypeTest extends BaseTest {
.containsEntry("display-price", 8.95D);
}
@Test
public void a_path_evaluation_can_be_returned_as_PATH_LIST() {
Configuration conf = Configuration.builder().options(AS_PATH_LIST).build();
List<String> pathList = using(conf).parse(JSON_DOCUMENT).read("$..author");
assertThat(pathList).containsExactly(
"$['store']['book'][0]['author']",
"$['store']['book'][1]['author']",
"$['store']['book'][2]['author']",
"$['store']['book'][3]['author']");
}
@Test(expected = ClassCastException.class)
public void class_cast_exception_is_thrown_when_return_type_is_not_expected() {
List<String> list = reader.read("$.store.book[0].author");
}
}

Loading…
Cancel
Save