I think I have a simple question, but can't seem to figure it out.
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?
My route is below;
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");
...and I'm invoking the route by the below;
ProducerTemplate template = camelContext.createProducerTemplate();
template.setDefaultEndpoint(camelContext.getEndpoint("direct:start"));
InvocationResult result = (InvocationResult)template.requestBodyAndHeader(payload, "methodName", methodName);
Payload is JSON, and the methodName is either listCases or listPersons in this example.
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.
Thanks,
Bic
unmarshall()
with Jackson. Do you have any issue with usingmarshall()
similarly? As long as the response can be marshalled by Jackson, it should be straightforward enough? – Cyäegha