JsonPath意外返回true

时间:2018-06-22 15:04:46

标签: java boolean-logic jsonpath rule

我正在使用 com.jayway.jsonpath 。当我创建类 JsonPathRule 的实例并调用 jsonPathRuleInstance.evaluate()时,我收到的是 true 而不是 false 。每次都在我的过滤器中

  

(x || y)&&(z)在x:true,y:true,z:false时为true。

但是

  

x && y为x时为假,y:假

我的样本杰森

{
    "a": 1,
    "b": 2
}

我面临问题的班级

public class JsonPathRule {

  private static final Configuration conf = initJsonPathConfiguration();

  private static Configuration initJsonPathConfiguration() {
    Configuration configuration = Configuration.defaultConfiguration();
    configuration.addOptions(Option.ALWAYS_RETURN_LIST, Option.DEFAULT_PATH_LEAF_TO_NULL);
    return configuration;
  }

  public boolean evaluate() {
  String facts = <Sample Json string HERE>;
  String jsonPathFilter = "$.[?(@.a == 1 || @.a == 1)&&(@.b == 1)]";
    List<String> results = JsonPath.using(conf).parse(facts).read(jsonPathFilter);
    return (results.size() > 0);
  }
}

0 个答案:

没有答案