问题
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);
回答1:
`.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)
来源:https://stackoverflow.com/questions/39981444/apache-camel-split-jsonarray-remove-the-double-quote