简体   繁体   中英

Mule esb 3.8 how to add variable into payload?

let say I have payload:

{ Name=User1, Age=29 }

and variable:

{ Address=Planet Earth}

I want to have a check if that variable not null then add it into payload. So final result will be:

{ Name=User1, Age=29, Address=Planet Earth }

How? Was try via payload.Put(variable) but that not allow me such.

With DataWeave using a Transform component you can use the expression: payload ++ flowVars.variable

If you don't want or can't use DataWeave then you can use a MEL expression that uses the Java method Map.putAll() of the Map interface. You can not use <set-payload> because it doesn't return a value. Instead you can use the <expression-component> component.

Example:

<expression-component doc:name="Expression"><![CDATA[payload.putAll(flowVars.variable)]]></expression-component>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM