Skip to main content

im trying the following:

<set-variable variableName="tempPayload" value="#payload" encoding="UTF-8" mimeType="application/json" doc:name="Store Payload temporarily"/>

<json:json-to-object-transformer returnClass="java.lang.Object" doc:name="JSON to Object"/>

<set-payload value="#flowVars.tempPayload" encoding="UTF-8" mimeType="application/json" doc:name="Set Payload back"/>

 

but it corrupts the payload somehow which causes following transform to break in the flow.

6 answers
  1. Sep 10, 2019, 7:18 PM

    In Mule 3 use the enricher. Here is an example that wraps the json to object in an enricher and extracts a value into a variable and leaves the payload intact:

     

    <flow name="test">

    <poll frequency="10000" doc:name="Poll">

    <logger level="ERROR" message="started" doc:name="Logger" />

    </poll>

     

    <set-payload doc:name="Set Payload"

    value="{&quot;myField&quot;:&quot;myValue&quot;}" />

    <enricher target="#[flowVars.myFieldVar]">

    <processor-chain>

    <json:json-to-object-transformer

    returnClass="java.util.HashMap" />

    <set-payload value="#[payload.myField]" />

    </processor-chain>

    </enricher>

     

    <choice>

    <when expression="#[flowVars.myFieldVar =='myValue']">

    <logger level="INFO" message="myField is equal to myValue" />

    </when>

    <otherwise>

    <logger level="INFO" message="meh" />

    </otherwise>

    </choice>

     

    <logger level="INFO" message="Payload is still original payload #payload" />

     

     

    </flow>

    LoggerMessageProcessor: myField is equal to myValue

    LoggerMessageProcessor: Payload is still original payload {"myField":"myValue"}

     Note you can also save multiple targets at once for setting multiple variables in one enricher. But the syntax is slightly different. Google the docs to find that syntax.

     

    Also note if you have multiple processors in your enricher they need to be wrapped in a processor-chain, like in the example.

0/9000