【发布时间】:2021-08-20 07:57:18
【问题描述】:
在我的 Apache Camel 应用程序中,我有多个条件来检查 JSON 中是否存在键。我想减少样板代码,因此我需要将我的Expressions 转换为Predicate。
我的代码Expressions:
.choice()
.when().jsonpath("$.score", true).to("direct:b")
.when().jsonpath("$.points", true).to("direct:b")
.otherwise().to("direct:c");
另请参阅:JSONPATH
我的代码Predicates:
.choice()
.when(PredicateBuilder.or(jsonpath("$.score", true), jsonpath("$.points", true))).to("direct:b")
.otherwise().to("direct:c");
另见:PREDICATES
但这不起作用,因为没有suppressExceptions 参数(请参阅BuilderSupport#jsonpath)。不幸的是,也没有exists 方法(参见ValueBuilder)。
如何编写 Predicate 来检查 JSON 中是否存在密钥?
【问题讨论】:
标签: apache-camel json-path-expression