com.jayway.jsonpath.Predicate Java Examples

The following examples show how to use com.jayway.jsonpath.Predicate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OperationIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenJsonPathWithCustomizedPredicate_whenReading_thenCorrect() {
    Predicate expensivePredicate = context -> Float.valueOf(context.item(Map.class)
        .get("price")
        .toString()) > 20.00;
    List<Map<String, Object>> expensive = JsonPath.parse(jsonDataSourceString)
        .read("$['book'][?]", expensivePredicate);
    predicateUsageAssertionHelper(expensive);
}
 
Example #2
Source File: JsonPathExpressionValidator.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
PathComponentAnalyzer(String pathFragment, LinkedList<Predicate> filterList) {
    this.pathFragment = pathFragment;
    this.filterList = filterList;
}
 
Example #3
Source File: JsonPathExpressionValidator.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
static PathToken analyze(String pathFragment, LinkedList<Predicate> filterList) {
    return new PathComponentAnalyzer(pathFragment, filterList).analyze();
}
 
Example #4
Source File: JsonPathExpressionValidator.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
public PathToken analyze() {

            if ("$".equals(pathFragment)) {
                return new RootPathToken();
            } else if ("..".equals(pathFragment)) {
                return new ScanPathToken();
            } else if ("[*]".equals(pathFragment)) {
                return new WildcardPathToken();
            } else if (".*".equals(pathFragment)) {
                return new WildcardPathToken();
            } else if ("[?]".equals(pathFragment)) {
                return new PredicatePathToken(filterList.poll());
            } else if (FILTER_PATTERN.matcher(pathFragment).matches()) {
                final int criteriaCount = Utils.countMatches(pathFragment, "?");
                List<Predicate> filters = new ArrayList<>(criteriaCount);
                for (int i = 0; i < criteriaCount; i++) {
                    filters.add(filterList.poll());
                }
                return new PredicatePathToken(filters);
            }

            this.i = 0;
            do {
                current = pathFragment.charAt(i);

                switch (current) {
                    case '?':
                        return analyzeCriteriaSequence4();
                    case '\'':
                        return analyzeProperty();
                    default:
                        if (Character.isDigit(current) || current == ':' || current == '-' || current == '@') {
                            return analyzeArraySequence();
                        }
                        i++;
                        break;
                }

            } while (i < pathFragment.length());

            //"Could not analyze path component: " + pathFragment
            return null;
        }
 
Example #5
Source File: JsonPathProvider.java    From bender with Apache License 2.0 4 votes vote down vote up
public static <T> T read(Object jsonObject, String pathStr, Predicate... filters) {
  JsonPath path = getPath(pathStr);
  return path.read(jsonObject);
}