[ 
https://issues.apache.org/jira/browse/CAMEL-25871?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Claus Ibsen resolved CAMEL-25871.
---------------------------------
    Resolution: Fixed

> camel-bean - a hint for an OGNL read on a List and on a variable that holds a 
> file
> ----------------------------------------------------------------------------------
>
>                 Key: CAMEL-25871
>                 URL: https://issues.apache.org/jira/browse/CAMEL-25871
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-bean
>            Reporter: Claus Ibsen
>            Assignee: Claus Ibsen
>            Priority: Minor
>             Fix For: 4.24.0
>
>
> Two errors of a Simple OGNL read give no hint, and a coding agent got stuck 
> on both in a night of runs against a local model (thousands of failed 
> exchanges in a few runs).
> *1. ${body.orderId} on a List*
> The body is the List of an unmarshalled JSON array, and the route wants the 
> order with an id:
> {noformat}
> Failed to invoke method: orderId on the message body of type 
> java.util.ArrayList due to: 
> org.apache.camel.component.bean.MethodNotFoundException: Method with name: 
> orderId not found on bean: [{orderId=ORD-1001, ...}, ...] of type: 
> java.util.ArrayList
> {noformat}
> The agent then made up methods, such as {{${body.find(o -> o.orderId == 
> header.id)}}} and {{${body.?[orderId == ...]}}}, with the same error. 
> {{${body[orderId]}}} on a List already gets a hint (CAMEL-25746), but the 
> method path does not.
> Fix: "(a List has no method or key orderId: pick an element first, such as 
> [0].orderId, or the element whose orderId has a given value with jsonpath, 
> such as jsonpath: "$[?(@.orderId == '${header.orderId}')]" with resultType 
> java.util.Map, or split it)". For a made-up method, the same with a 
> placeholder field name.
> *2. ${variable.customer[name]} on a variable that holds a file*
> pollEnrich with variableReceive puts the polled file in the variable (a 
> GenericFile), not its data:
> {noformat}
> Key: name not found in bean: GenericFile[C-482.json] of type: 
> org.apache.camel.component.file.GenericFile using OGNL path [[name]]
> {noformat}
> On the body, the same read already says to unmarshal the file first 
> (CAMEL-25749). On a variable it says nothing.
> Fix: "(the value is the file as read (a GenericFile), not its data: unmarshal 
> it first, for example with json, then read the key; a variable is 
> unmarshalled in place with variableSend and variableReceive set to its name, 
> such as unmarshal: {json: {}, variableSend: customer, variableReceive: 
> customer})". The same for a java.io.File.
> _Claude Code on behalf of davsclaus_



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

Reply via email to