Mule ESB DataMapper:将输入“&”替换为“/”并将其分配给输出

Mule ESB DataMapper: Replace the input '&' with '/' and assign it to the output

我有一个 Mule ESB 项目,我在其中获取 JSON 格式的数据并将其转换为 CSV。在转换过程中,我想将其中一个属性中的“&”替换为“/”。我尝试了以下方法:

output.Department = input.department.replace('&', '/');

但是 mule 抛出以下错误:

output.Department = input.department.replace('&', '/');" failed. (org.mule.api.expression.ExpressionRuntimeException)
org.mule.el.mvel.DataMapperExpressionLanguage:71 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/expression/ExpressionRuntimeException.html)
4. Message: Transform failed! (org.jetel.exception.TransformException)
org.jetel.component.DataRecordTransform:132 (null)

我还尝试了以下变体,但都失败并显示相同的错误消息:

output.Department = input.department.replace("&", "/");

编辑: 输入字段 'Department' 的值将如下所示:'Application & Development Team'。目标系统不接受'&',这就是我们需要将其更改为'/'的原因,这样输出值就会像'Application / Development Team'.

我的环境是 Windows 7,带有 Mule ESB EE 3.6.2 运行时的 Anypoint Studio 5.1.2,我在 Studio 中 运行 这个。关于如何用斜杠 ('/') 替换符号 (&) 有什么想法吗?

这个表达方式很适合我。它失败的唯一原因是 department 是否为空。添加空检查:

output.Department = isnull(input.department) ? input.department : input.department.replace('&', '/');