在dataweave中将{“ abc”:“”}转换为<abc xsi:nil =“ true” />

问题描述

我有以下输入 输入: JSON:

{
  "abc": ""
}

预期输出: XML:

<abc xsi:nil="true"/>

使用的数据织法:

%dw 2.0
output application/xml
ns xsi http://www.w3.org/2001/XMLSchema-instance
---
(if(payload.abc == "")
            (abc @(xsi#'nil': true):{})
        else
            null)

I am getting an error. Please help me with this

解决方法

定义dataweave输出时,可以使用'writeNilOnNull'writer属性:

%dw 2.0
output application/xml writeNilOnNull=true
---
payload

请注意,此属性只会为null属性(在您提供的示例中,空字符串不为null)设置nil。

以下屏幕截图显示了此行为:

DW writeNilOnNull example

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...