title: Apache Camel JSON Marshalling to POJO Java Bean
body: <p>I think I have a simple question, but can't seem to figure it out.</p>
  
  <p>I'm invoking a POJO with a class created from unmarshalling JSON as the parameter for the method. The question is, how do I marshal the return from the method back to JSON?</p>
  
  <p>My route is below;</p>
  
  <pre><code>from("direct:start")
   .choice()
    .when(header("methodname").isEqualTo("listCases"))
     .unmarshal().json(JsonLibrary.Jackson, UserDetails.class)
     .to("bean:com.xxx.BeanA")
    .when(header("methodName").isEqualTo("listPersons"))
     .unmarshal().json(JsonLibrary.Jackson, CaseDetails.class)
     .to("bean:com.xxx.BeanB");
  </code></pre>
  
  <p>...and I'm invoking the route by the below;</p>
  
  <pre><code>ProducerTemplate template = camelContext.createProducerTemplate();
  template.setDefaultEndpoint(camelContext.getEndpoint("direct:start"));
  InvocationResult result = (InvocationResult)template.requestBodyAndHeader(payload, "methodName", methodName);
  </code></pre>
  
  <p>Payload is JSON, and the methodName is either listCases or listPersons in this example.</p>
  
  <p>My InvocationResult class is generic and contains a String returnCode attribute as well as an object reference to the object I would like to be converted to JSON. This object will be different depending on whether listCases or listPersons is executed.</p>
  
  <p>Thanks,</p>
  
  <p>Bic</p>