在我的 Apache Camel 应用程序中,我有多个条件来检查 JSON 中是否存在键。我想减少样板代码,因此我需要将我Expression
的 s 转换为Predicate
.
我的代码与Expression
s:
.choice()
.when().jsonpath("$.score", true).to("direct:b")
.when().jsonpath("$.points", true).to("direct:b")
.otherwise().to("direct:c");
另请参阅:JSONPATH
我的代码与Predicate
s:
.choice()
.when(PredicateBuilder.or(jsonpath("$.score", true), jsonpath("$.points", true))).to("direct:b")
.otherwise().to("direct:c");
另请参阅:谓词
但这不起作用,因为没有suppressExceptions
参数(请参阅 参考资料BuilderSupport#jsonpath
)。不幸的是,也没有方法exists
(请参阅 参考资料ValueBuilder
)。
如何编写Predicate
用于检查 JSON 中是否存在密钥的代码?