• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JsonPathException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.jayway.jsonpath.JsonPathException的典型用法代码示例。如果您正苦于以下问题:Java JsonPathException类的具体用法?Java JsonPathException怎么用?Java JsonPathException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JsonPathException类属于com.jayway.jsonpath包,在下文中一共展示了JsonPathException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: setProperty

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
@Override
public void setProperty(Object obj, Object key, Object value) {
    try {
        if (isMap(obj))
            toJsonObject(obj).put(key.toString(), createJsonElement(value));
        else {
            JSONArray array = toJsonArray(obj);
            int index;
            if (key != null) {
                index = key instanceof Integer ? (Integer) key : Integer.parseInt(key.toString());
            } else {
                index = array.length();
            }
            if (index == array.length()) {
                array.put(createJsonElement(value));
            } else {
                array.put(index, createJsonElement(value));
            }
        }
    } catch (JSONException e) {
        throw new JsonPathException(e);
    }
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:24,代码来源:JsonOrgJsonProvider.java


示例2: length

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
@Override
public int length(final Object obj) {
    if (isArray(obj)) {
        return toJsonArray(obj).size();
    } else if (isMap(obj)) {
        return toJsonObject(obj).entrySet().size();
    } else {
        if (obj instanceof JsonElement) {
            JsonElement element = toJsonElement(obj);
            if (element.isJsonPrimitive()) {
                return element.toString().length();
            }
        }
    }

    throw new JsonPathException("length operation can not applied to " + obj != null ? obj.getClass().getName()
                                                                                     : "null");
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:19,代码来源:GsonJsonProvider.java


示例3: parse

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
public Map<String, String> parse(String payload){
    Map<String, String> result = new HashMap<String, String>();
    if(StringUtils.isNotEmpty(payload)) {
        DocumentContext documentContext = JsonPath.parse(payload);

        for (JsonParameter jsonParameter : jsonParameters) {
            if (StringUtils.isEmpty(jsonParameter.getJsonPath())) {
                result.put(jsonParameter.getEnvVarName(), payload);
            } else {
                try {
                    result.put(jsonParameter.getEnvVarName(), documentContext.read(jsonParameter.getJsonPath()).toString());
                } catch (JsonPathException jpe) {
                    logger.log("Error while parsing path %s for environment variable %s.%nStacktrace:%n%s%n",
                            jsonParameter.getJsonPath(), jsonParameter.getEnvVarName(), LogUtils.getStackTrace(jpe));
                }
            }
        }
    }

    return result;
}
 
开发者ID:XT-i,项目名称:aws-lambda-jenkins-plugin,代码行数:22,代码来源:JsonPathParser.java


示例4: countMatches

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
@Test
public void countMatches () throws ManipulationException, IOException
{
    String pluginsPath = "$..plugins";
    String reposURLPath = "$.repository.url";
    try
    {
        DocumentContext doc = jsonIO.parseJSON( pluginFile );

        List o = doc.read ( pluginsPath );
        assertTrue( o.size() == 1 );

        o = doc.read ( reposURLPath );
        assertTrue( o.size() == 1 );
    }
    catch (JsonPathException e)
    {
        throw new ManipulationException( "Caught JsonPath", e );
    }
}
 
开发者ID:release-engineering,项目名称:pom-manipulation-ext,代码行数:21,代码来源:JSONIOTest.java


示例5: getArrayIndex

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
@Override
public Object getArrayIndex(Object obj, int idx) {
    try {
        return toJsonArray(obj).get(idx);
    } catch (JSONException e) {
        throw new JsonPathException(e);
    }
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:9,代码来源:JsonOrgJsonProvider.java


示例6: setArrayIndex

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
@Override
public void setArrayIndex(Object array, int index, Object newValue) {
    try {
        if (!isArray(array)) {
            throw new UnsupportedOperationException();
        } else {
            toJsonArray(array).put(index, createJsonElement(newValue));
        }
    } catch (JSONException e) {
        throw new JsonPathException(e);
    }
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:13,代码来源:JsonOrgJsonProvider.java


示例7: getMapValue

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
@Override
public Object getMapValue(Object obj, String key) {
    try {
        JSONObject jsonObject = toJsonObject(obj);
        Object o = jsonObject.opt(key);
        if (o == null) {
            return UNDEFINED;
        } else {
            return unwrap(o);
        }
    } catch (JSONException e) {
        throw new JsonPathException(e);
    }
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:15,代码来源:JsonOrgJsonProvider.java


示例8: getPropertyKeys

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
@Override
public Collection<String> getPropertyKeys(Object obj) {
    JSONObject jsonObject = toJsonObject(obj);
    List<String> keys = new ArrayList<String>();
    try {
        for (int i = 0; i < jsonObject.names().length(); i++) {
            String key = (String) jsonObject.names().get(i);
            keys.add(key);

        }
        return keys;
    } catch (JSONException e) {
        throw new JsonPathException(e);
    }
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:16,代码来源:JsonOrgJsonProvider.java


示例9: length

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
@Override
public int length(Object obj) {
    if (isArray(obj)) {
        return toJsonArray(obj).length();
    } else if (isMap(obj)) {
        return toJsonObject(obj).length();
    } else {
        if (obj instanceof String) {
            return ((String) obj).length();
        }
    }
    throw new JsonPathException("length operation can not applied to " + obj != null ? obj.getClass().getName() : "null");
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:14,代码来源:JsonOrgJsonProvider.java


示例10: toJson

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
@Override
public String toJson(Object obj) {
    if (!(obj instanceof JsonNode)) {
        throw new JsonPathException("Not a JSON Node");
    }
    return obj.toString();
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:8,代码来源:JacksonJsonNodeJsonProvider.java


示例11: length

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
@Override
public int length(Object obj) {
    if (isArray(obj)) {
        return toJsonArray(obj).size();
    } else if (isMap(obj)) {
        return toJsonObject(obj).size();
    } else {
        if (obj instanceof TextNode) {
            TextNode element = (TextNode) obj;
            return element.size();
        }
    }
    throw new JsonPathException("length operation can not applied to " + obj != null ? obj.getClass().getName() : "null");
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:15,代码来源:JacksonJsonNodeJsonProvider.java


示例12: setProperty

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
/**
 * Sets a value in an object
 *
 * @param obj   an object
 * @param key   a String key
 * @param value the value to set
 */
@SuppressWarnings("unchecked")
public void setProperty(Object obj, Object key, Object value) {
    if (isMap(obj))
        ((Map) obj).put(key.toString(), value);
    else {
        throw new JsonPathException("setProperty operation cannot be used with " + obj!=null?obj.getClass().getName():"null");
    }
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:16,代码来源:AbstractJsonProvider.java


示例13: length

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
/**
 * Get the length of an array or object
 *
 * @param obj an array or an object
 * @return the number of entries in the array or object
 */
public int length(Object obj) {
    if (isArray(obj)) {
        return ((List) obj).size();
    } else if (isMap(obj)){
        return getPropertyKeys(obj).size();
    } else if(obj instanceof String){
        return ((String)obj).length();
    }
    throw new JsonPathException("length operation cannot be applied to " + obj!=null?obj.getClass().getName():"null");
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:17,代码来源:AbstractJsonProvider.java


示例14: toIterable

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
/**
 * Converts given array to an {@link Iterable}
 *
 * @param obj an array
 * @return an Iterable that iterates over the entries of an array
 */
@SuppressWarnings("unchecked")
public Iterable<? extends Object> toIterable(Object obj) {
    if (isArray(obj))
        return ((Iterable) obj);
    else
        throw new JsonPathException("Cannot iterate over " + obj!=null?obj.getClass().getName():"null");
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:14,代码来源:AbstractJsonProvider.java


示例15: parse

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
@Override
public Object parse(final InputStream jsonStream, final String charset) throws InvalidJsonException {

    try {
        return PARSER.parse(new InputStreamReader(jsonStream, charset));
    } catch (UnsupportedEncodingException e) {
        throw new JsonPathException(e);
    }
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:10,代码来源:GsonJsonProvider.java


示例16: setCache

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
public static void setCache(Cache cache){
    notNull(cache, "Cache may not be null");
    synchronized (CacheProvider.class){
        if(CacheProvider.cache != null){
            throw new JsonPathException("Cache provider must be configured before cache is accessed.");
        } else {
            CacheProvider.cache = cache;
        }
        cachingEnabled = !(CacheProvider.cache instanceof NOOPCache);
    }
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:12,代码来源:CacheProvider.java


示例17: GsonMappingProvider

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
public GsonMappingProvider() {
    super();
    try {
        Class.forName("com.google.gson.Gson");
        this.factory = new Callable<Gson>() {
            @Override
            public Gson call() {
                return new Gson();
            }
        };
    } catch (ClassNotFoundException e) {
        logger.error("Gson not found on class path. No converters configured.");
        throw new JsonPathException("Gson not found on path", e);
    }
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:16,代码来源:GsonMappingProvider.java


示例18: evaluate

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
@Override
public boolean evaluate(ValueNode left, ValueNode right, Predicate.PredicateContext ctx) {
    if(!left.isBooleanNode() && !right.isBooleanNode()){
        throw new JsonPathException("Failed to evaluate exists expression");
    }
    return left.asBooleanNode().getBoolean() == right.asBooleanNode().getBoolean();
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:8,代码来源:EvaluatorFactory.java


示例19: toValueNode

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
public static ValueNode toValueNode(Object o){
    if(o == null) return ValueNode.NULL_NODE;
    if(o instanceof ValueNode) return (ValueNode)o;
    if(o instanceof Class) return createClassNode((Class)o);
    else if(isPath(o)) return new PathNode(o.toString(), false, false);
    else if(isJson(o)) return createJsonNode(o.toString());
    else if(o instanceof String) return createStringNode(o.toString(), true);
    else if(o instanceof Character) return createStringNode(o.toString(), false);
    else if(o instanceof Number) return createNumberNode(o.toString());
    else if(o instanceof Boolean) return createBooleanNode(o.toString());
    else if(o instanceof Pattern) return createPatternNode((Pattern)o);
    else throw new JsonPathException("Could not determine value type");
}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:14,代码来源:ValueNode.java


示例20: getKeyName

import com.jayway.jsonpath.JsonPathException; //导入依赖的package包/类
private Optional<String> getKeyName(final EC2InstanceContext context) {
    try {
        return Optional.ofNullable(trimToNull(JsonPath.read(context.getInstanceJson(), "$.keyName")));
    } catch (final JsonPathException ignored) {
        return Optional.empty();
    }
}
 
开发者ID:zalando-stups,项目名称:fullstop,代码行数:8,代码来源:KeyPairPlugin.java



注:本文中的com.jayway.jsonpath.JsonPathException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ClientResponse类代码示例发布时间:2022-05-23
下一篇:
Java ProgressMonitor类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap