Apache Camel 在 CONTENT_TYPE 为 application/json 时修改 JSON
Apache Camel modifies JSON when CONTENT_TYPE is application/json
我正在使用 Apache Camel 构建我的 REST-API,我将 "bindingMode(RestBindingMode.json)" 用于我的带有 jetty 的 restConfiguration。在我的一个处理器中,我将 "out" 对象的 "body" 设置为一个实际上是 JSON 对象的字符串。当我将 Exchange.CONTENT_TYPE 设置为 "text/plain" 时,响应按预期出现并且可以直接解析为 JSON 对象。
{"mockBasicData":"123"}
但是当我将 Exchange.CONTENT_TYPE 设置为 "application/json" 时,或者如果我根本不设置它,Camel 会操纵 body 并使其脱离,就好像它已经不是 JSON 对象。
{\"mockBasicData\":\"123\"}
有没有办法避免在 Camel 中自动转义,因为我需要 CONTENT_TYPE 为 "application/json"?
RestBinding 的典型用途是指定从 POJO 到 json 或 xml 的编组 。如果我理解正确的话,你是在将 json 字符串正文转换为 json,对吗?
如果是这样,您是否尝试过使用 JSON Object 自身设置 out 对象的主体?
另请注意以下事项:
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.
直接将"bindingMode(RestBindingMode.off)"添加到路线(而不是休息()!)为我解决了这个问题。
我正在使用 Apache Camel 构建我的 REST-API,我将 "bindingMode(RestBindingMode.json)" 用于我的带有 jetty 的 restConfiguration。在我的一个处理器中,我将 "out" 对象的 "body" 设置为一个实际上是 JSON 对象的字符串。当我将 Exchange.CONTENT_TYPE 设置为 "text/plain" 时,响应按预期出现并且可以直接解析为 JSON 对象。
{"mockBasicData":"123"}
但是当我将 Exchange.CONTENT_TYPE 设置为 "application/json" 时,或者如果我根本不设置它,Camel 会操纵 body 并使其脱离,就好像它已经不是 JSON 对象。
{\"mockBasicData\":\"123\"}
有没有办法避免在 Camel 中自动转义,因为我需要 CONTENT_TYPE 为 "application/json"?
RestBinding 的典型用途是指定从 POJO 到 json 或 xml 的编组 。如果我理解正确的话,你是在将 json 字符串正文转换为 json,对吗? 如果是这样,您是否尝试过使用 JSON Object 自身设置 out 对象的主体?
另请注意以下事项:
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.
直接将"bindingMode(RestBindingMode.off)"添加到路线(而不是休息()!)为我解决了这个问题。