Camel-restlet/rest-dsl中的转义序列

Camel-restlet/rest-dsl中的转义序列,rest,apache-camel,dsl,restlet,jbossfuse,Rest,Apache Camel,Dsl,Restlet,Jbossfuse,骆驼路线- rest("/servicenow").post("/{operation}").consumes("application/json").type(Model.class).produces(MediaType.APPLICATION_JSON).to("direct:servicenow"); from("direct:servicenow") .setHeader("operationSelector", simple("${header.operation}"))

骆驼路线-

rest("/servicenow").post("/{operation}").consumes("application/json").type(Model.class).produces(MediaType.APPLICATION_JSON).to("direct:servicenow");
from("direct:servicenow")
    .setHeader("operationSelector", simple("${header.operation}"))
    .process(new PreProcessor())
    .recipientList().simple("servicenow://${header.instance}?userName=${header.name}&password=${header.password}&apiUrl=${header.apiUrl}")
    .process(new PostProcessor());
和后处理器类-

    Object msg = exchange.getIn().getBody();
GsonBuilder builder = new GsonBuilder();
builder.setLenient();
Gson gson = builder.create();
JsonElement element = gson.toJsonTree(msg);
JsonObject result = new JsonObject();
if (element.isJsonArray()) {
    JsonArray array = (JsonArray) element;
    result.add("result", array);
    System.out.println(result.toString());
    exchange.getOut().setBody(result.toString());
} else {
    result.add("result", element);
    System.out.println(result.toString());
    exchange.getOut().setBody(result.toString());
}
返回到客户端时,示例结果在JSON数组/对象中包含转义序列

"{\"result\":[{\"parent\":\"\",\"made_sla\":\"true\",\"caused_by\":\"\"

如果需要,请帮助修改restlet配置,以便在JSON响应中获得响应而不使用转义序列

不要使用这一行:

JsonObject result = new JsonObject();
使用此首选答案:

Map<DataType,DataType> result = new HashMap<DataType,DataType>();
result.put("result", array);
exchange.getOut().setBody(result);
Map result=newhashmap();
result.put(“result”,数组);
exchange.getOut().setBody(结果);

restlet将把map对象绑定到一个jsonObject。

而不是
result。toString
,只需使用resultPossible duplicate of Hi Kiran,只需result不起作用。Response-com.fasterxml.jackson.databind.JsonMappingException:JsonObject(通过com.google.gson.JsonObject[“asString”]),位于com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:210),位于com.fasterxml.jackson.databind.JsonMappingException.wrapWithPath(JsonMappingException.java:177)如果您自己进行编组/解编组,请尝试设置
bindingMode=off
(操作属性)。