I am parsing an json and verify array length like below
from("direct:parseJson")
.setHeader("numberOfBooks").jsonpath("$..books.length()", int.class)
.choice()
.when( simple("${header.numberOfBooks} == '1'"))
.log("One book")
.otherwise()
.log("multiple");
Above Code works, but i am looking for option if we can avoid line 2 with below
.when( simple("${jsonpath(' $..books.length() ', int.class)} == 1") )
its throwing error
Caused by:
org.apache.camel.language.simple.types.SimpleIllegalSyntaxException:
Unknown function: jsonpath(' $..books.length() ', int.class) == 1 at
location 0
${jsonpath(' $..books.length() ', int.class)} == 1
second try i set header with constant to verify simple expression works or not
.when().jsonpath("$..books.length() > ${header.numberOfBooks}")
Caused by: com.jayway.jsonpath.InvalidPathException: Could not parse token starting at position 18
at com.jayway.jsonpath.internal.path.PathCompiler.fail(PathCompiler.java:616) ~[json-path-2.4.0.jar:2.4.0]
at com.jayway.jsonpath.internal.path.PathCompiler.readNextToken(PathCompiler.java:152) ~[json-path-2.4.0.jar:2.4.0]