0

I'm trying to suppress all the exceptions when evaluating a JSON path. but when I upgrade the JSON path lib to 2.7, it seems like it is not working as expected. For example:

var node = objectMapper.readTree("{\"test\" :  null}");

    JsonPath.using(Configuration.builder()
        .options(Option.SUPPRESS_EXCEPTIONS).build())
        .parse(node.toString())
        .read("$.test[?(@ != null)]");

we got an exception thrown.

Filter: [?] can not be applied to primitives. Current context is: null
com.jayway.jsonpath.InvalidPathException: Filter: [?] can not be applied to primitives. Current context is: null

related issue : https://github.com/json-path/JsonPath/issues/908

1 Answers1

0

It seems like the new update removed the try/catch statement to check the SUPPRESS_EXCEPTION option. So you can use the try/catch to check it by itself. like this one:

try {
  JsonPath.using(Configuration.builder()
          .options(Option.SUPPRESS_EXCEPTIONS).build())
      .parse(node.toString())
      .read("$.test[?(@ != null)]");
} catch (JsonPathException ex) {
  if (is suppress exception) {
    return 'default value';
  } 
  throw  ex;
}
Gaoranger
  • 1
  • 1