Check the size of a List/Map from Apache camel route

We can check the size of a java.util.List using below code.

  .when(simple("${body.size() > 10}"))
    .log(LoggingLevel.INFO, "List size is greater than 10")
  .when(simple("${body.size() > 0}"))
    .log(LoggingLevel.INFO, "List size is greater than 0")
    .log(LoggingLevel.INFO, "List is empty")

Same logic can be used for other collection objects in Java.

Please not that you have to add null check before this if you expect null values. Applying null check in camel routes is explained here:

Leave a Reply

Your email address will not be published. Required fields are marked *