0
votes

I'm building my REST-API with Apache Camel and I use "bindingMode(RestBindingMode.json)" for my restConfiguration with jetty. In one of my Processors I set the "body" of the "out" object with a String that actually is a JSON object. When I set the Exchange.CONTENT_TYPE to "text/plain" the response comes in as expected and can directly be parsed to a JSON object.

{"mockBasicData":"123"}

But when I set the Exchange.CONTENT_TYPE to "application/json" or if I don't set it at all, Camel manipulates the body and escapes it, like it wouldn't already be a JSON object.

{\"mockBasicData\":\"123\"}

Is there a way to avoid that auto-escaping in Camel, as I need the CONTENT_TYPE to be "application/json"?

2
have you tried using RestBindingMode.Auto ?Sunand Padmanabhan
Yes, doesn‘t help.Sebastian Lang

2 Answers

2
votes

The typical use of the RestBinding is to specify the marshalling from POJO to json or xml. If I understand correctly what you said, you are converting a json string body to json, right ? If so, have you tried to set the body of the out object with the JSON Object it-self ?

Please also note the following:

From Camel 2.16.3 onwards the binding from POJO to JSon/JAXB will only happen if the content-type header includes json or xml. This allows you to specify a custom content-type if the message body should not attempt to be marshalled using the binding. This is useful if, for example, the message body is a custom binary payload.

2
votes

Adding "bindingMode(RestBindingMode.off)" directly to the route (not to rest()!) solved it for me.