问题描述
在 Dataweave 1.0 中,我需要将“地址”值设置为基于属性“address.length”截断的文本。例如,如果 address.length 大于 25,则 customer.addressLine1 需要截断为前 25 个字符,否则将 Address 设置为“customer.addressLine1”中的值。
代码:
property file --> address.length=25
(ns2#Address: customer.addressLine1[0.."${address.length}" as :number-1] when ((((sizeOf (customer.addressLine1)) > ("${address.length}" as :number)))) otherwise customer.addressLine1)
例外:
Root Exception stack trace:
com.mulesoft.weave.mule.exception.weaveExecutionException: Exception while executing:
(ns2#Address: customer.addressLine1[0.."25" as :number-1] when ((((sizeOf (customer.addressLine1)) > ("25" as :number)))) otherwise customer.addressLine1
^
Type mismatch for 'Descendants Selector ..' operator
found :number
required :array.
解决方法
(ns2#Address: customer.addressLine1[0 to "${address.length}" as :number - 1] when (sizeOf (customer.addressLine1)) > ("${address.length}" as :number) otherwise customer.addressLine1)
试试上面的代码。范围选择器不正确。应该是 [0 to "${address.length}" as :number - 1]
错误表明您正在使用后代选择器。应该使用范围选择器。