Java JsonPath grab InvalidPathException in code, you must be catching Java 7's java.nio.file.Invalid...

 

 


I am using JsonPath and am able to parse my data and get the values when the path provided is correct.

However when I provide an incorrect path (user input) the program terminates. I dont want that to happen. Is there anyway for me to catch this exceptions and continue with the next steps?

try
        {
            String value = JsonPath.read(jsonText, jsonPath);

            System.out.println(value);
        }
        catch(InvalidPathException e)
        {
            System.out.println("ERROR<InvalidPathException>: "+e.getMessage());
        }

I get following error with invalid path:

Exception in thread "main" com.jayway.jsonpath.InvalidPathException: invalid path
at com.jayway.jsonpath.internal.filter.FieldFilter.filter(FieldFilter.java:59)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:182)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:202)
at com.jayway.jsonpath.JsonPath.read(JsonPath.java:307)
at office.jsonPathparse.main(jsonPathparse.java:37)

This exception seems to be comming from FieldFilter which is jar's class.

 

 


If I understood you correctly and your catch block isn't being executed, you must be catching Java 7's java.nio.file.InvalidPathException instead of JsonPath's com.jayway.jsonpath.InvalidPathException. Double check your import statements.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值