I have a setup with Swagger and the Rest DSL. Swagger uses the OutType(MyType.class) to annotate the API with the return type. However, there are times when I wish to return something else to the caller, e.g. an error message with a HTTP response code.
Take the following Route as an example: RestDefinition privateAPI = rest(ServiceConstants.PRIVATE_API_VERSION_1).description("Private (internal) REST services for MyServices."); privateAPI.get("/fetchsomething").description("Lists stuff from some service") .outTypeList(MyPojoForSomething.class) .route().routeId("A descriptive ID") .choice() .when(header(ServiceConstants.REQUEST_VALIDATED).isEqualTo("TRUE")) .bean(GoAheadAndFillAMyPojoForSomething-into-body.class) .otherwise().bean(ErrorMessageConstructor.class); ------- * An Interceptor validates the incoming message and sets the Header constant to TRUE or FALSE. * The ErrorMessageConstructor constructs a proper message and puts it as a String into the body together with a correct HTTP code (E.g. Not-Found). Problem: The marshaller, uses outTypeList to determine the way to convert the Message body to Json. If in the above example, the request was "FALSE", the marshaller (I am using Jackson) tries to marshall a String to a MyPojoForSomething.class. The content of the String I have constructed for the error is in this case: "Missing properties in HTTP Header." This results in an error: com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Missing': was expecting ('true', 'false' or 'null') at [Source: java.io.ByteArrayInputStream@67618968; line: 1, column: 9] at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1419) ........ -- View this message in context: http://camel.465427.n5.nabble.com/Rest-DSL-OutType-in-case-of-error-message-problem-tp5759864.html Sent from the Camel - Users mailing list archive at Nabble.com.