ray
ray

Reputation: 4250

Mule JSON Payload null check in Choice Filter

Am I doing anything wrong here? Even the json payload is [], it's going to the default instead of Error log.

<choice doc:name="If Payload is Null">
    <when expression="#[payload == empty]">
        <mule-logger-module:logger-exception message="Null Payload" doc:name="Log Error"/>
    </when>
    <otherwise>
        <mule-logger-module:log-default message="Payload Received" type="EXIT" doc:name="Log End"/>
    </otherwise>
</choice>

Upvotes: 1

Views: 1337

Answers (1)

Ryan Carter
Ryan Carter

Reputation: 11606

Convert to a Array of Maps first, then use the MEL expressions to test empty:

<json:json-to-object-transformer
            returnClass="java.util.HashMap[]" doc:name="JSON to Object" />
<choice doc:name="If Payload is Null">
<when expression="#[payload == empty]">
    <mule-logger-module:logger-exception message="Null Payload" doc:name="Log Error"/>
</when>
<otherwise>
    <mule-logger-module:log-default message="Payload Received" type="EXIT" doc:name="Log End"/>
</otherwise>

Upvotes: 2

Related Questions