[
https://issues.apache.org/jira/browse/CAMEL-25900?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen reassigned CAMEL-25900:
-----------------------------------
Assignee: Claus Ibsen
> camel-jbang - AI tools: lead to the jsonpath filter with resultType
> java.util.Map for the one element of a list
> ---------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-25900
> URL: https://issues.apache.org/jira/browse/CAMEL-25900
> Project: Camel
> Issue Type: Improvement
> Components: camel-jbang
> Reporter: Claus Ibsen
> Assignee: Claus Ibsen
> Priority: Minor
> Fix For: 4.24.0
>
>
> A REST example of the benchmark asks for one order out of a JSON list by its
> id (GET /orders/{id}, 404 when unknown). It failed 12 of 12 times, on two
> nights. The camel-jbang AI tools saw the earlier hints, but the model still
> wrote paths that give the wrong answer:
> * {{$[?(@.orderId == '${header.id}')][0]}}: Jayway applies an index after a
> filter to each element the filter matched, so this gives an empty list (200
> with []).
> * {{$[?(@.orderId == '${header.id}')] && size() > 0}}: && outside the filter
> is no JsonPath (500).
> * {{${body[0].orderId}}}: the List hint offered [0] first, so the model took
> the first element.
> The recipe (a filter with resultType java.util.Map: the element when one
> matches, null when none does) was in the docs, but the tools did not lead to
> it.
> Proposal:
> * The source check (camel_validate_source and the write tools) reports an
> index after a filter: "an index after a filter gives an empty list in
> JsonPath ... leave the index out and set resultType: java.util.Map". It also
> reports && or || outside a filter: "&& and || work inside a filter only ...;
> to test whether a filter matched, set resultType: java.util.Map, and check
> ${body} == null in a choice".
> * camel_eval_expression of a jsonpath filter adds a note that a filter gives
> a list also for one match, and that in a route resultType: java.util.Map
> gives the one element.
> * camel_catalog_doc jsonpath answers the recipe in usage.
> * camel-bean: the hint for ${body.orderId} on a List leads with the jsonpath
> recipe, and [0] comes after it.
> * camel_catalog_find for a wrong header name (CamelHttpStatusCode and
> similar) names the right one, CamelHttpResponseCode
> (Exchange.HTTP_RESPONSE_CODE).
> _Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v8.20.10#820010)