0

我需要将下面 JSON 中的用户名与 Mule ESB 3.8.3 中的 flowVars 进行比较

{"id":"users_0001","username":"0001","firstName":"AB","lastName":"C","email":"abc@abc.com","enabled":true}

在选择运算符中使用此表达式

<choice doc:name="Choice">
    <when expression="#[json:[0]/username != flowVars.username]">
        <flow-ref name="put account" doc:name="put account"/>
    </when>
    <otherwise>
        <flow-ref name="do nothing" doc:name="do nothing"/>
    </otherwise>
 </choice>

在调试过程中,我可以看到 json:[0]/username 和 flowVars.username 都返回相同的值,但是为什么在比较它们时总是返回 false?

这是我评估它们时的结果

flowVars.username == "0001", returns true
flowVars.username == '0001', returns true
flowVars.username == 0001, returns true
json:[0]/username = 0001, returns true
json:[0]/username = "0001", returns false
json:[0]/username = '0001', returns false
json:[0]/username != flowVars.username, returns true
json:[0]/username = flowVars.username, returns false
4

1 回答 1

0

我会避免使用 #[json] 工具,而只是将传入的 JSON 转换为 HashMap。您的生活会更轻松,而且使用 HashMap 更容易。

根据文档:https ://docs.mulesoft.com/mule-user-guide/v/3.7/mule-expression-language-tips

JSON 处理 MEL 不直接支持 JSON。json-to-object-transformer 可以将 JSON 有效负载转换为易于使用 MEL 解析的简单数据结构的层次结构。

在你的情况下,是这样的:

    <json:json-to-object-transformer returnClass="java.util.HashMap" doc:name="JSON to Object"/>
    <choice doc:name="Choice">
        <when expression="#[payload.username != flowVars.username]">
            <flow-ref name="put account" doc:name="put account"/>
        </when>
        <otherwise>
             <flow-ref name="do nothing" doc:name="do nothing"/>
        </otherwise>
    </choice>
于 2017-08-09T07:04:45.013 回答