Package com.jayway.jsonpath

Examples of com.jayway.jsonpath.InvalidPathException


            }
        } else {
            String evalPath = currentPath + "[" + Utils.join(", ", "'", properties) + "]";

            if (!isLeaf()) {
                throw new InvalidPathException("Multi properties can only be used as path leafs: " + evalPath);
            }

            Object merged = ctx.jsonProvider().createMap();
            for (String property : properties) {
                Object propertyVal;
View Full Code Here


    public void evaluate(String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx) {
        if(model == null){
            throw new PathNotFoundException("The path " + currentPath + " is null");
        }
        if (!ctx.jsonProvider().isArray(model)) {
            throw new InvalidPathException(format("Filter: %s can only be applied to arrays. Current context is: %s", toString(), model));
        }

        try {
            int idx;
            int input;
View Full Code Here

        notEmpty(path, "Path may not be null empty");
        try {
            path = path.trim();

            if (path.endsWith("..")) {
                throw new InvalidPathException("A path can not end with a scan.");
            }

            LinkedList<Predicate> filterList = new LinkedList<Predicate>(asList(filters));

            if (path.charAt(0) != '$' && path.charAt(0) != '@') {
                path = "$." + path;
            }

            boolean isRootPath = (path.charAt(0) == '$');

            if (path.charAt(0) == '@') {
                path = "$" + path.substring(1);
            }

            if (path.length() > 1 &&
                    path.charAt(1) != '.' &&
                    path.charAt(1) != '[') {
                throw new InvalidPathException("Invalid path " + path);
            }

            String cacheKey = path + isRootPath + filterList.toString();
            Path p = cache.get(cacheKey);
            if (p != null) {
                if (logger.isDebugEnabled()) logger.debug("Using cached path: " + cacheKey);
                return p;
            }

            RootPathToken root = null;


            int i = 0;
            int positions;
            String fragment = "";

            do {
                char current = path.charAt(i);

                switch (current) {
                    case SPACE:
                        throw new InvalidPathException("Space not allowed in path");
                    case DOCUMENT:
                        fragment = "$";
                        i++;
                        break;
                    case BRACKET_OPEN:
                        positions = fastForwardUntilClosed(path, i);
                        fragment = path.substring(i, i + positions);
                        i += positions;
                        break;
                    case PERIOD:
                        i++;
                        if (path.charAt(i) == PERIOD) {
                            //This is a deep scan
                            fragment = "..";
                            i++;
                        } else {
                            positions = fastForward(path, i);
                            if (positions == 0) {
                                continue;

                            } else if (positions == 1 && path.charAt(i) == '*') {
                                fragment = new String("[*]");
                            } else {
                                assertValidFieldChars(path, i, positions);

                                fragment = PROPERTY_OPEN + path.substring(i, i + positions) + PROPERTY_CLOSE;
                            }
                            i += positions;
                        }
                        break;
                    case ANY:
                        fragment = new String("[*]");
                        i++;
                        break;
                    default:
                        positions = fastForward(path, i);

                        fragment = PROPERTY_OPEN + path.substring(i, i + positions) + PROPERTY_CLOSE;
                        i += positions;
                        break;
                }
                if (root == null) {
                    root = (RootPathToken) PathComponentAnalyzer.analyze(fragment, filterList);
                } else {
                    root.append(PathComponentAnalyzer.analyze(fragment, filterList));
                }

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

            Path pa = new CompiledPath(root, isRootPath);

            cache.put(cacheKey, pa);

            return pa;

        } catch (Exception ex){
            throw new InvalidPathException(ex);
        }
    }
View Full Code Here

                }


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

            throw new InvalidPathException("Could not analyze path component: " + pathFragment);
        }
View Full Code Here

                }
                mem = c;
                curr++;
            }
            if(openBrackets != 0 || openSquareBracket != 0){
                throw new InvalidPathException("Filter brackets are not balanced");
            }
            return new int[]{start, end};
        }
View Full Code Here

                    current = pathFragment.charAt(++i);
                }
                String function = buffer.toString();
                buffer.setLength(0);
                if (!function.equals("size") && !function.equals("length")) {
                    throw new InvalidPathException("Invalid function: @." + function + ". Supported functions are: [(@.length - n)] and [(@.size() - n)]");
                }
                while (current != ')') {
                    if (current == ' ') {
                        current = pathFragment.charAt(++i);
                        continue;
View Full Code Here

                    handleArrayIndex(idx, currentPath, model, ctx);
                }
                idx++;
            }
        } else {
            throw new InvalidPathException(format("Filter: %s can not be applied to primitives. Current context is: %s", toString(), model));
        }
    }
View Full Code Here

    private transient int index = 0;

    public PathTokenizer(String jsonPath) {

        if (INVALID_PATH_PATTERN.matcher(jsonPath).matches()) {
            throw new InvalidPathException("Invalid path: " + jsonPath);
        }

        if (!jsonPath.startsWith("$") && !jsonPath.startsWith("$[")) {
            jsonPath = "$." + jsonPath;
        }
View Full Code Here

            return;
        }
        char peek = peek();
        for (char check : invalidChars) {
            if (check == peek) {
                throw new InvalidPathException("Char: " + peek + " at current position is not valid!");
            }
        }
    }
View Full Code Here

    private void assertValidPeek(boolean acceptEmpty, char... validChars) {
        if (isEmpty() && acceptEmpty) {
            return;
        }
        if (isEmpty()) {
            throw new InvalidPathException("Path is incomplete");
        }
        boolean found = false;
        char peek = peek();
        for (char check : validChars) {
            if (check == peek) {
                found = true;
                break;
            }
        }
        if (!found) {
            throw new InvalidPathException("Path is invalid");
        }
    }
View Full Code Here

TOP

Related Classes of com.jayway.jsonpath.InvalidPathException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.