Examples of JsonProvider


Examples of com.jayway.jsonpath.spi.JsonProvider

        super(condition);
    }

    @Override
    public Object filter(Object obj, Configuration configuration) {
        JsonProvider jsonProvider = configuration.getProvider();
        Object result = jsonProvider.createArray();

        if (jsonProvider.isArray(obj)) {
            for (Object current : jsonProvider.toIterable(obj)) {
                for (Object value : jsonProvider.toIterable(current)) {
                    jsonProvider.setProperty(result, jsonProvider.length(result), value);
                }
            }
        } else {
            for (Object value : jsonProvider.toIterable(obj)) {
                jsonProvider.setProperty(result, jsonProvider.length(result), value);
            }
        }
        return result;
    }
View Full Code Here

Examples of com.jayway.jsonpath.spi.JsonProvider



    @Override
    public Object filter(Object obj, Configuration configuration) {
        JsonProvider jsonProvider = configuration.getProvider();
        Iterable<Object> src = null;
        try {
            src = jsonProvider.toIterable(obj);
        } catch (ClassCastException e){
            throw new PathNotFoundException("The path fragment '" + this.condition + "' can not be applied to a JSON object only a JSON array.", e);
        }
        Object result = jsonProvider.createArray();
        for (Object item : src) {
            if (isMatch(item, configuration, conditionStatements)) {
                jsonProvider.setProperty(result, jsonProvider.length(result), item);
            }
        }
        return result;
    }
View Full Code Here

Examples of com.jayway.jsonpath.spi.JsonProvider

        this.split = condition.split("','");
    }

    @Override
    public Object filter(Object obj, Configuration configuration, LinkedList<Filter> filters, boolean inArrayContext) {
        JsonProvider jsonProvider = configuration.getProvider();
        if (jsonProvider.isArray(obj)) {
            if (!inArrayContext) {
                throw new PathNotFoundException("Path '" + condition + "' is being applied to an array. Arrays can not have attributes.");
            } else {
                Object result = jsonProvider.createArray();
                for (Object current : jsonProvider.toIterable(obj)) {
                    if (jsonProvider.isMap(current)) {
                       
                        Collection<String> keys = jsonProvider.getPropertyKeys(current);

                        if(split.length == 1){
                            if (keys.contains(condition)) {
                                Object o = jsonProvider.getProperty(current, condition);

                                boolean isArr = jsonProvider.isArray(o);
                                boolean isEnd = pathToken.isEndToken();
                                if (isArr && !isEnd) {
                                    for(Object item : jsonProvider.toIterable(o)){
                                        jsonProvider.setProperty(result, jsonProvider.length(result), item);
                                    }
                                } else {
                                    jsonProvider.setProperty(result, jsonProvider.length(result), jsonProvider.getProperty(current, condition));
                                }
                            }
                        } else {
                            Object res = jsonProvider.createMap();
                            for (String prop : split) {
                                if (keys.contains(prop)) {
                                    jsonProvider.setProperty(res, prop, jsonProvider.getProperty(current, prop));
                                }
                            }
                            jsonProvider.setProperty(result, jsonProvider.length(result), res);
                        }
                    }
                }
                return result;
            }
        } else if (jsonProvider.isMap(obj)){

            Collection<String> keys = jsonProvider.getPropertyKeys(obj);
            if(!keys.contains(condition) && split.length == 1){

                if(configuration.getOptions().contains(Option.THROW_ON_MISSING_PROPERTY)){
                    throw new PathNotFoundException("Path '" + condition + "' not found in the current context:\n" + jsonProvider.toJson(obj));
                }

                if(pathToken.isEndToken()){
                    return null;
                } else {
                    throw new PathNotFoundException("Path '" + condition + "' not found in the current context:\n" + jsonProvider.toJson(obj));
                }
            } else {

                if(split.length == 1){
                    return jsonProvider.getProperty(obj, condition);
                } else {
                    Object res = jsonProvider.createMap();
                    for (String prop : split) {
                        if(keys.contains(prop)){
                          jsonProvider.setProperty(res, prop, jsonProvider.getProperty(obj, prop));
                        }
                    }
                    return res;
                }
            }
View Full Code Here

Examples of com.jayway.jsonpath.spi.JsonProvider

    }


    @Override
    public Object filter(Object obj, Configuration configuration) {
        JsonProvider jsonProvider = configuration.getProvider();
        if (jsonProvider.isArray(obj)) {
            return obj;
        } else {
            return jsonProvider.getProperty(obj, condition);
        }
    }
View Full Code Here

Examples of com.jayway.jsonpath.spi.JsonProvider

        this.path = JsonPath.compile(trim(trimmedCondition, 5, 2));
    }

    @Override
    public Object filter(Object obj, Configuration configuration) {
        JsonProvider jsonProvider = configuration.getProvider();

        //[?(@.isbn)]
        Iterable<Object> src = jsonProvider.toIterable(obj);
        Object result = jsonProvider.createArray();

        for (Object item : src) {
            if(jsonProvider.isMap(item)){
                try{
                    path.read(item, Configuration.builder().options(Option.THROW_ON_MISSING_PROPERTY).jsonProvider(jsonProvider).build());
                    jsonProvider.setProperty(result, jsonProvider.length(result), item);
                } catch (PathNotFoundException e){
                    // the path was not found in the item
                }
            }
        }
View Full Code Here

Examples of com.jayway.jsonpath.spi.JsonProvider

     * @param filterItems items to filter
     * @param configuration the json provider configuration that is used to create the result list
     * @return the filtered list
     */
    public Object doFilter(Iterable<T> filterItems, Configuration configuration) {
        JsonProvider provider = configuration.getProvider();
        Object result = provider.createArray();
        for (T filterItem : filterItems) {
            if (accept(filterItem, configuration)) {
                provider.setProperty(result, provider.length(result), filterItem);
            }
        }
        return result;
    }
View Full Code Here

Examples of com.jayway.jsonpath.spi.JsonProvider

    }


    @Override
    public Object filter(Object obj, Configuration configuration) {
        JsonProvider jsonProvider = configuration.getProvider();

        Object result = jsonProvider.createArray();

        if (trimmedCondition.contains(OPERATOR)) {
            if (trimmedCondition.startsWith(OPERATOR)) {
                String trimmedCondition = trim(this.trimmedCondition, 1, 0);
                int get = Integer.parseInt(trimmedCondition);
                for (int i = 0; i < get; i++) {
                    try {
                        jsonProvider.setProperty(result, jsonProvider.length(result), jsonProvider.getProperty(obj, i));
                    } catch (IndexOutOfBoundsException e){
                        break;
                    }
                }
                return result;

            } else if (trimmedCondition.endsWith(OPERATOR)) {
                String trimmedCondition = trim(SPACE.matcher(this.trimmedCondition).replaceAll(""), 0, 1);
                int get = Integer.parseInt(trimmedCondition);
                if(get > 0 || usesLenght){
                    if(get > 0){
                        get = get * -1;
                    }
                    return jsonProvider.getProperty(obj, jsonProvider.length(obj) + get);
                } else {
                    int start = jsonProvider.length(obj) + get;
                    int stop = jsonProvider.length(obj);

                    if(start < 0){
                        start = 0;
                    }

                    for (int i = start; i < stop; i ++){
                        jsonProvider.setProperty(result, jsonProvider.length(result), jsonProvider.getProperty(obj, i));
                    }
                    return result;
                }

            } else {
                String[] indexes = this.trimmedCondition.split(OPERATOR);

                int start = Integer.parseInt(indexes[0]);
                int stop = Integer.parseInt(indexes[1]);

                for (int i = start; i < stop; i ++){
                    try {
                        jsonProvider.setProperty(result, jsonProvider.length(result), jsonProvider.getProperty(obj, i));
                    } catch (IndexOutOfBoundsException e){
                        break;
                    }
                }
                return result;
            }
        } else {
            String[] indexArr = COMMA.split(trimmedCondition);

            //if(obj == null || jsonProvider.length(obj) == 0){
            if(obj == null){
                return result;
            }

            try {
                if (indexArr.length == 1) {
                    /*
                    if(jsonProvider.length(obj) == 0){
                        throw new PathNotFoundException("Array index [" + indexArr[0] + "] not found in path");
                    }
                    */

                    return jsonProvider.getProperty(obj, indexArr[0]);
                } else {
                    for (String idx : indexArr) {
                        jsonProvider.setProperty(result, jsonProvider.length(result), jsonProvider.getProperty(obj, idx.trim()));
                    }
                    return result;
                }
            } catch (IndexOutOfBoundsException e){
                throw new PathNotFoundException("Array index " + indexArr + " not found in path", e);
View Full Code Here

Examples of com.jayway.jsonpath.spi.JsonProvider

        super(condition);
    }

    @Override
    public Object filter(Object obj, Configuration configuration) {
        JsonProvider jsonProvider = configuration.getProvider();
        Object result = jsonProvider.createArray();
        scan(obj, result, jsonProvider);

        return result;
    }
View Full Code Here

Examples of com.khs.sherpa.json.service.JsonProvider

    for(RequestEvent event: events) {
      event.before(applicationContext, request, response);
    }
   
    ServletOutputStream output = null;
    JsonProvider jsonProvider = null;
    try {
      output = response.getOutputStream();
      jsonProvider = applicationContext.getManagedBean(JsonProvider.class);
    } catch (Exception e) {
      throw new RuntimeException(e);
View Full Code Here

Examples of org.apache.cxf.jaxrs.provider.JSONProvider

        return (Book)u.unmarshal(is);
    }
   
    @SuppressWarnings("unchecked")
    private Book readJSONBookFromInputStream(InputStream is) throws Exception {
        JSONProvider provider = new JSONProvider();
        return (Book)provider.readFrom((Class)Book.class, Book.class, new Annotation[]{},
                                 MediaType.APPLICATION_JSON_TYPE, null, is);
       
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.