问题
I have two different payloads here in format:
{"addressLine1":"POSBUS 007","addressLine3":"-1","postalCode":"1200"}
{"email":"xxxx@xxx.net"}.
If I use the scatter gather i get the following payload:
[{"addressLine1":"POSBUS 007","addressLine3":"-1","postalCode":"1200"}, {"email":"xxxx@xxx.net"}]
But what I want to do is merge those two payloads into one payload like for instance:
{"addressLine1":"POSBUS 007","addressLine3":"-1","postalCode":"1200", "email":"xxxx@xxx.net"}
回答1:
There are several good ways to solve this problem. Here's one using groovy:
- In each route of the scatter-gather, add a
<json:json-to-object-transformer returnClass="java.util.HashMap" />
to transform the JSON payload to a Map. - After the scatter-gather, add the following to transform the list of maps into a single map:
<set-payload value="#[groovy:payload.inject([:]) {result, part -> result.putAll(part); result}]" />
来源:https://stackoverflow.com/questions/25868364/i-merge-two-different-payloads-into-one-payload