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

Claus Ibsen updated CAMEL-24916:
--------------------------------
    Fix Version/s: 4.23.0

> camel-bean: ${body.name} on a Map reads the key when there is no such method
> ----------------------------------------------------------------------------
>
>                 Key: CAMEL-24916
>                 URL: https://issues.apache.org/jira/browse/CAMEL-24916
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-bean
>            Reporter: Claus Ibsen
>            Priority: Major
>             Fix For: 4.23.0
>
>
> In the local-model benchmark (s11 and s12, 5 runs each of four HTTP rungs) 
> the loudest runtime failure by far is dot access on a Map body:
> {noformat}
> Failed to invoke method: sku on {sku=CAMEL-MUG, qty=42, price=12.5} of type 
> java.util.LinkedHashMap
> Method with name: sku not found on bean: {sku=CAMEL-MUG, qty=42, price=12.5}
> {noformat}
> 3582 occurrences in s12, 3492 in s11 - more than every other runtime error 
> together. It comes from routes that unmarshal JSON and then read a field with 
> {{$\{body.sku\}}} instead of {{$\{body[sku]\}}}.
> CAMEL-24838 already added a hint to the message ("the value is a Map: a key 
> is read with [sku]"), and it does not stop it happening, because dot access 
> on a map is what jq, JavaScript, Groovy and most JSON tooling do.
> Proposal: in {{BeanExpression}}, when the OGNL method call fails with a 
> method-not-found and the bean is a {{Map}} that contains a key of that name, 
> read the key instead of throwing. Additive:
> * a method still wins, so {{$\{body.size\}}} on a Map keeps calling 
> {{size()}} and nothing that works today changes
> * an unknown name still throws, because the key must be present - a typo is 
> still reported
> * only the path that throws today can now return a value
> This helps humans as much as models: it is a frequent question on the mailing 
> list and in chat.



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

Reply via email to