In my Apache Camel application I have multiple conditions checking the existence of keys in a JSON. I want to reduce the boiler plate code, therefore I need to transform my Expression
s to a Predicate
.
My code with Expression
s:
.choice()
.when().jsonpath("$.score", true).to("direct:b")
.when().jsonpath("$.points", true).to("direct:b")
.otherwise().to("direct:c");
See also: JSONPATH
My code with Predicate
s:
.choice()
.when(PredicateBuilder.or(jsonpath("$.score", true), jsonpath("$.points", true))).to("direct:b")
.otherwise().to("direct:c");
See also: PREDICATES
But this is not working, because there is no suppressExceptions
parameter (see BuilderSupport#jsonpath
). Unfortunately, there is also no exists
mehod (see ValueBuilder
).
How can I write a Predicate
for checking the existence of a key in a JSON?