I merge two different payloads into one payload

两盒软妹~` 提交于 2019-12-08 12:30:49

问题


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:

  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}]" />


来源:https://stackoverflow.com/questions/25868364/i-merge-two-different-payloads-into-one-payload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!