Andre Coetzee
Andre Coetzee

Reputation: 1310

I merge two different payloads into one payload

I have two different payloads here in format:

{"addressLine1":"POSBUS 007","addressLine3":"-1","postalCode":"1200"}
{"email":"[email protected]"}. 

If I use the scatter gather i get the following payload:

[{"addressLine1":"POSBUS 007","addressLine3":"-1","postalCode":"1200"}, {"email":"[email protected]"}]

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":"[email protected]"}

Upvotes: 0

Views: 2300

Answers (1)

Ryan Hoegg
Ryan Hoegg

Reputation: 2475

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

Upvotes: 1

Related Questions