I am trying to create a Camel REST service via Java DSL that can consume/produce both json and xml and the JSON works but I receive the an error when I try to retrieve the result in XML.
RestMethods Class:
public class RestMethods extends RouteBuilder {
@Override
public void configure() throws Exception {
rest()
.bindingMode(RestBindingMode.json_xml)
.consumes("application/json, application/xml")
.produces("application/json, application/xml")
.get("/rating")
.toD("direct:getRatingByClient");
}
Route Implementation:
public class GetRatingByClientRoute extends RouteBuilder{
// Use to created the mock
private final ObjectMapper objectMapper = new ObjectMapper();
@Override
public void configure() throws Exception {
from("direct:getRatingByClient")
// Request
.to("log:init")
// Mediation
.process(exchange -> {
// TODO Implement route
TestEntity test = new TestEntity();
test.setTestAttribute("Teste");
exchange.getOut().setBody(test);
// Response
.to("log:end");
}
}
When I run with Content-Type application/json works like a charm. But, when i run with Content-Type application/xml i got this error: java.io.IOException: org.apache.camel.InvalidPayloadException: No body available of type: javax.xml.bind.JAXBElement but has value: class GetRatingByClientRouteResponse
Follow the requisition that I´m testing: curl -X GET \ 'http://localhost:8080/credits/v1/rating?client_cpf_cnpj=11111111111' \ -H 'Accept: application/xml' \ -H 'Cache-Control: no-cache' \ -H 'Content-Type: application/xml'