将字符串转换为布尔值 Mule4 Dataweave

Convert string to boolean Mule4 Dataweave

我有 mule4 DW 表达式,我想将其转换为布尔值“因为布尔值”无法正常工作,或者可能是我放错了地方。

DW 表达式:

%dw 2.0
output application/java
ns ns0 http://www.demandware.com/xml/impex/order/2006-10-31
---
[{
    Id: (payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute" filter(item) -> (item.@"attribute-id" == "sscAccountid")) [0],
    Marketing_Opt_in__c: (payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute" filter(item) -> (item.@"attribute-id" == "newsLetterRegistration")) [0] //***This output I want to convert into Boolean***
    
}]

XML 标签

<custom-attribute attribute-id="newsLetterRegistration">false</custom-attribute>
[{
Id: (payload.order."custom-attributes".*"custom-attribute" filter(item) -> (item.@"attribute-id" == "sscAccountid"))[0],
Marketing_Opt_in__c: (payload.order."custom-attributes".*"custom-attribute" filter(item) -> (item.@"attribute-id" == "newsLetterRegistration"))[0]
 ~= 'True'  //***This output I want to convert into Boolean***
}]

为了使其不区分大小写,将比较的两边都转换为一种情况,如大写

upper((item.@"attribute-id" == "newsLetterRegistration"))[0])
     ~= 'TRUE' 

另一种方法是使用 Java 布尔值 class 自动执行此转换。

(item.@"attribute-id" == "newsLetterRegistration"))[0] as Boolean