本文整理汇总了Java中com.jayway.jsonpath.Filter类的典型用法代码示例。如果您正苦于以下问题:Java Filter类的具体用法?Java Filter怎么用?Java Filter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Filter类属于com.jayway.jsonpath包,在下文中一共展示了Filter类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: issues_by_state_and_number
import com.jayway.jsonpath.Filter; //导入依赖的package包/类
/**
* Issues that are open and have a number >= 30
*/
@Test
public void issues_by_state_and_number () {
Filter<?> filter = Filter.filter(
Criteria.where("state")
.is("open")
.and("number")
.gte(30));
List<Object> issuesByLabelAndAuthor = JsonPath.read(githubIssues, "$.[?]", filter);
logger.info(issuesByLabelAndAuthor);
assertEquals(1, issuesByLabelAndAuthor.size());
}
示例2: testJsonPathManual
import com.jayway.jsonpath.Filter; //导入依赖的package包/类
@Test
public void testJsonPathManual() throws URISyntaxException, IOException {
document = Configuration.defaultConfiguration()
.jsonProvider().parse(FileUtils.readContent("general/book.json"));
List<String> authors = JsonPath.read(document, "$.store.book[*].author");
assertEquals(
Arrays.asList("Nigel Rees", "Evelyn Waugh", "Herman Melville", "J. R. R. Tolkien"),
authors);
assertEquals("Nigel Rees", JsonPath.read(document, "$.store.book[0].author"));
assertEquals("Evelyn Waugh", JsonPath.read(document, "$.store.book[1].author"));
List<Map<String, Object>> expensiveBooks = JsonPath
.using(Configuration.defaultConfiguration())
.parse(FileUtils.readContent("general/book.json"))
.read("$.store.book[?(@.price > 10)]", List.class);
assertEquals(2, expensiveBooks.size());
String json = "{\"date_as_long\" : 1411455611975}";
Date date = JsonPath.parse(json).read("$['date_as_long']", Date.class);
assertEquals("23 Sep 2014 07:00:11 GMT", date.toGMTString());
List<Map<String, Object>> books = JsonPath.read(document, "$.store.book[?(@.price < 10)]");
assertEquals(2, books.size());
Filter cheapFictionFilter = filter(where("category").is("fiction").and("price").lte(10D));
books = JsonPath.read(document, "$.store.book[?]", cheapFictionFilter);
assertEquals(1, books.size());
Filter fooOrBar = filter(where("category").exists(true)).or(where("price").exists(true));
books = JsonPath.read(document, "$.store.book[?]", fooOrBar);
assertEquals(4, books.size());
Filter fooAndBar = filter(where("category").exists(true))
.and(where("price").exists(true));
books = JsonPath.read(document, "$.store.book[?]", fooAndBar);
assertEquals(4, books.size());
}
示例3: testOr
import com.jayway.jsonpath.Filter; //导入依赖的package包/类
@Test
public void testOr() throws URISyntaxException, IOException {
document = Configuration.defaultConfiguration()
.jsonProvider().parse(FileUtils.readContent("general/test.json"));
String providerProxy = "$.['ore:Proxy'][?(@['edm:europeanaProxy'][0] == 'false')][?]";
String idPath = "$.identifier";
String dataProviderPath = "$.['ore:Aggregation'][0]['edm:dataProvider'][0]";
String datasetPath = "$.sets[0]";
Filter fooOrBar = filter(where("identifier").exists(true)).or(Criteria.where("sets").exists(true));
Map<String, Object> books = JsonPath.read(document, "$", fooOrBar);
assertEquals(9, books.size());
Filter titleOrDescription = filter(where("dc:title").exists(true)).or(Criteria.where("dc:description").exists(true));
JSONArray proxy = JsonPath.read(document, providerProxy, titleOrDescription);
assertEquals(1, proxy.size());
Filter titleAndDescription = filter(where("dc:title").exists(true)).and(Criteria.where("dc:description").exists(true));
proxy = JsonPath.read(document, providerProxy, titleAndDescription);
assertEquals(0, proxy.size());
proxy = JsonPath.read(document, providerProxy, filter(where("['dc:title1']").exists(true)));
assertEquals(0, proxy.size());
titleOrDescription = filter(where("['dc:title1']").exists(true)).and(Criteria.where("['dc:description']").exists(true));
proxy = JsonPath.read(document, providerProxy, titleOrDescription);
assertEquals(0, proxy.size());
}
示例4: exists
import com.jayway.jsonpath.Filter; //导入依赖的package包/类
/**
* Verifies the existence of a property within a JSON document.
*
* @param jsonPath
* The jsonPath to the requested property.
* @param filters
* Optional filters that allow to select certain items for lists.
*
* @return <b>true</b> if the path to the property exists, <b>false</b> if
* not.
*/
public boolean exists( String jsonPath, Filter<?>... filters )
{
try
{
return get( jsonPath, filters ) == null ? false : true;
}
catch ( PathNotFoundException e )
{
return false;
}
}
示例5: compile
import com.jayway.jsonpath.Filter; //导入依赖的package包/类
public static Filter compile(String filterString) {
FilterCompiler compiler = new FilterCompiler(filterString);
return new CompiledFilter(compiler.compile());
}
示例6: JsonPathSelector
import com.jayway.jsonpath.Filter; //导入依赖的package包/类
public JsonPathSelector(ObjectMapper mapper, String jsonPath, Filter... filters) {
super(JsonPath.compile(jsonPath, filters));
this.mapper = mapper;
this.jsonPathConfig = Configuration.builder().jsonProvider(new Jackson2JsonProvider(mapper)).build();
}
示例7: J
import com.jayway.jsonpath.Filter; //导入依赖的package包/类
public static Selector J(String jsonPath, Filter... filters) {
return jsonPathSelector(jsonPath, filters);
}
示例8: jsonPathSelector
import com.jayway.jsonpath.Filter; //导入依赖的package包/类
public static Selector jsonPathSelector(String jsonPath, Filter... filters) {
return new JsonPathSelector(jsonPath, filters);
}
示例9: get
import com.jayway.jsonpath.Filter; //导入依赖的package包/类
/**
* Gets a property of the JSON via a specified jsonPath and an optional
* filter. This method uses the
* {@link JsonPath#read(String, String, Filter...)} method. On details how
* to use the filter please see <a
* href="http://code.google.com/p/json-path">JSON-Path documentation</a>.
*
* @param <T>
* Auto calculated return type.
* @param jsonPath
* The jsonPath to the requested property.
* @param filters
* Optional filters that allow to select certain items for lists.
*
* @return The value of the requested JSON property.
*/
public <T> T get( String jsonPath, Filter<?>... filters )
{
return JsonPath.read( this.toString(), jsonPath, filters );
}