I merge two different payloads into one payload

2019-06-13 19:22发布

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条回答
男人必须洒脱
2楼-- · 2019-06-13 19:54

There are several good ways to solve this problem. Here's one using groovy:

  1. 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.
  2. 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}]" />
查看更多
登录 后发表回答