Apache camel getbody as custom class

回眸只為那壹抹淺笑 提交于 2019-12-04 15:18:35

As far as I remember you cannot get generic list with getBody. This might work:

List<String> oldstr = (List<String>)exchange.getIn().getBody(List.class);

or even better you can make camel extract body for you with @Body annotation:

public static List<HashMap<String, Integer>> hashTokens(final Exchange exchange, @Body List<String> oldStr) {
    //Create a key value hashmap from accumulated string list
    return new ArrayList<>();
}

Regarding your last question check out sub-section "Using POJOs as AggregationStrategy"/ "Different body types", from http://camel.apache.org/aggregator2.html

You could try sth like:

.pollEnrich("seda:foo", 1000, AggregationStrategies.beanAllowNull(MyUserAppender.class, "addUsers"))

public static final class MyUserAppender {

public List addUsers(List<String> names, User user) {
    if (names == null) {
        names = new ArrayList();
    }
    names.add(user.getName());
    return names;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!