Claus Ibsen created CAMEL-24841:
-----------------------------------

             Summary: jsonpath: a comparison written as the path ($.status == 
'paid') should say that jsonpath is a path and how to write the condition
                 Key: CAMEL-24841
                 URL: https://issues.apache.org/jira/browse/CAMEL-24841
             Project: Camel
          Issue Type: Improvement
          Components: camel-jsonpath, camel-jbang
            Reporter: Claus Ibsen


A condition on a JSON body, written the way people first write it:

{code:yaml}
- choice:
    when:
      - expression:
          jsonpath:
            expression: "$.status == 'paid'"
{code}

fails at runtime with the Jayway message

{code}
com.jayway.jsonpath.InvalidPathException: Use bracket notion ['my prop'] if 
your property contains blank characters. position: 2
{code}

which talks about a property with blanks that does not exist. What happened: a 
jsonpath is a path, not a comparison. The condition is written as a filter, 
{{$[?(@.status == 'paid')]}}, or after {{unmarshal: json:}} as {{simple: 
"${body[status]} == 'paid'"}}.

Two places to say so:
* {{camel validate yaml}} (and the camel-jbang-mcp validation tool) can parse 
the jsonpath expressions with Jayway as it parses Simple today, and translate 
this case: "Line 17: jsonpath is a path, not a comparison: for a condition 
write $[?(@.status == 'paid')], or unmarshal the JSON and write simple: 
${body[status]} == 'paid'".
* At runtime, {{camel-jsonpath}} can wrap the InvalidPathException with the 
same sentence when the expression contains a comparison operator.

Found in the round-2 local-model benchmark on the camel-jbang-examples ladder 
(filter-and-multicast). The same file-processing step in the Java DSL gets the 
same Jayway message.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to