Apache Camel 拆分 JSONArray 去除双引号 [英] Apache Camel split JSONArray remove the double quote
问题描述
我使用 JsonPathExpression 拆分了 JSONArray,但结果删除了每个 JSON 中的每个双引号,这是我的 RouteBuilder.
from("timer:scheduler?repeatCount=1").to("http:localhost:8901/rest/getData").split(new JsonPathExpression("$.[*]")).process(新处理器(){@java.lang.Overridepublic void process(Exchange exchange) 抛出异常 {字符串输入 = exchange.getIn().getBody(String.class);exchange.getIn().setBody(input);}}).unmarshal().json(JsonLibrary.Jackson, Map.class).log("${body}");
我只想使用 Jackson 解组那些 JSON,但您可能知道,Jackson 不会解析那些没有双引号的 JSON,是的,我可能允许 Jackson 解析没有双引号,但我更喜欢 JSON 有它.它还将 :
更改为 =
.
REST 调用的响应是这样的.
<预><代码>[{v_KDKANWIL":空,"v_GJJ": "CRJ"},{"v_KDKANWIL": "002","v_GJJ": "CRJ"}]拆分和处理后就变成这样了(只是第一个JSON).
<代码>{v_KDKANWIL=null,v_GJJ=CRJ}
我怀疑不仅是拆分,还有处理器,因为我使用 String 类型设置了新主体.
提前致谢.
编辑
啊,笨蛋,应该不是String而是Map,所以这个.
String input = exchange.getIn().getBody(String.class);
变成这样.
Map input = exchange.getIn().getBody(String.class);
`.split()` 将数据拆分为 java.util.map.使用 Jackson 或 Gson 将拆分后的数据编组以将其转换为 JSON.我遇到了同样的问题,并添加了 `marshal()` 解决了这个问题..marshal().json(JsonLibrary.Jackson)
I've split the JSONArray using JsonPathExpression, but the result removed every double quote in each JSON, here is my RouteBuilder.
from("timer:scheduler?repeatCount=1")
.to("http:localhost:8901/rest/getData")
.split(new JsonPathExpression("$.[*]"))
.process(new Processor() {
@java.lang.Override
public void process(Exchange exchange) throws Exception {
String input = exchange.getIn().getBody(String.class);
exchange.getIn().setBody(input);
}
})
.unmarshal().json(JsonLibrary.Jackson, Map.class)
.log("${body}");
I just want to unmarshal those JSON using Jackson, but as you might know, Jackson will not parse those JSON without double quote, yes, I might allow Jackson to parse without double quote, but I prefer the JSON to have it. Also it changes the :
to =
.
The response from REST call are like this.
[
{
"v_KDKANWIL": null,
"v_GJJ": "CRJ"
},
{
"v_KDKANWIL": "002",
"v_GJJ": "CRJ"
}
]
After splitting and processing it become like this (Just the first JSON).
{
v_KDKANWIL=null,
v_GJJ=CRJ
}
I suspect not just the split, but also in the processor because I set new body using String type.
Thanks in advance.
EDIT
Ah, stupid me, it should not be a String but Map, so this.
String input = exchange.getIn().getBody(String.class);
Become this.
Map input = exchange.getIn().getBody(String.class);
`.split()` splits data into java.util.map. Marshal data after split to convert it to JSON using Jackson or Gson. I faced the same issue and adding `marshal()` resolved the issue.
.marshal().json(JsonLibrary.Jackson)
这篇关于Apache Camel 拆分 JSONArray 去除双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!