title: Apache Camel serialize Java String/ArrayList to JSON object with jackson
body: <p>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</p>
  
  <p>Here is piece of my class:</p>
  
  <pre><code>public class MyBean {
  
  private String jsonStrings;
  List&lt;String&gt; jsonStringsArray = new ArrayList&lt;String&gt;();
  
  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);
      }
  }
  }
  </code></pre>
  
  <p>Thanks a lot</p>