Skip to content
𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ

Share the knowledge

𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ

Share the knowledge

Apache Camel – Index of Map or List from camel routes

Posted on March 15, 2017September 20, 2021 By sastrija

From inside a camel route we can retrieve the value by using its index easily.

To retrieve an item from a list by using index, use below code which will reads the list object in the exchange body and retrieves the value in position 2.

simple("${body[2].name}")

To retrieve an item from a map having String as key, use below code:

simple("${body[foo].empName}")

Here in the above example the key used isΒ foo. Suppose my key contains spaces, likeΒ foo bar. In those cases you needs to enclose those keys with quotes.

For example:

simple("${body['foo bar'].empName}")

In case there is no keywordΒ foo in the map, code will throw NullPointerException. In those cases use null safe operator.

simple("${body[foo]?.empName}")

Camel also provides a keywordΒ last to retrieve the last item of the collection.

simple("${body[last]?.empName}")

 

Related

Uncategorized

Post navigation

Previous post
Next post
©2026 𝓒π“ͺ𝓼𝓽𝓻𝓲𝓳π“ͺ | WordPress Theme by SuperbThemes