2017-08-09 45 views
0

我需要從以下JSON的flowVars在騾子ESB 3.8.3比較flowVars值JSONPath值在騾子ESB

{"id":"users_0001","username":"0001","firstName":"AB","lastName":"C","email":"[email protected]","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] /用戶名& 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 

回答

0

我會避免使用#[JSON]工具,只是變換傳入的JSON成一個HashMap。你的生活會更容易,加上使用HashMap更容易。

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

JSON處理 MEL對JSON沒有直接的支持。 JSON到對象變換器可以將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>