首页 > 解决方案 > 选择过滤器中的 Mule JSON Payload null 检查

问题描述

我在这里做错什么了吗?即使 json 有效负载是 [],它也会使用默认值而不是错误日志。

<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>

标签: jsonmulemule-esb

解决方案


首先转换为 Maps 数组,然后使用 MEL 表达式测试为空:

<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>


推荐阅读