I am currently working with Apache Camel and I am creating a route in which I am parsing XML and enriching it with JSON string. So far so good. After enrichment I am joining JSON strings. First idea was to use ArrayList and the other one was to use string separated by comma. This was no problem, but I need to return JSON object which is then used by REST
Here is piece of my class:
public class MyBean {
private String jsonStrings;
List<String> jsonStringsArray = new ArrayList<String>();
public void addEnrichSourceToString(Exchange exchange) {
Boolean isCompleted = (Boolean) exchange.getProperty("CamelSplitComplete");
String incomingString = exchange.getIn().getBody(String.class);
this.jsonStringsArray.add(exchange.getIn().getBody(String.class));
this.jsonStrings += incomingString + ",";
if (isCompleted) {
this.jsonStrings = "{\"MyNode\": [" + this.jsonStrings.substring(4, this.jsonStrings.length() - 1) + "]}";
exchange.getOut().setBody(this.jsonStrings);
}
}
}
Thanks a lot