【问题标题】:Replacing Null with Blank blank in Dataweave 2.0在 Dataweave 2.0 中用空白替换 Null
【发布时间】:2019-02-04 05:26:14
【问题描述】:

我必须在 dataweave 2.0 中将 null 替换为空白,我尝试了很多组合但出现错误。

附上截图供大家参考。

请提供任何相同的指针。

谢谢。

【问题讨论】:

标签: mule mule-studio mule-el mule-esb mule-cluster


【解决方案1】:

这是因为您将空白字符串分配给 dValue.doctorId 而不是 (doctorId)。同样使用default 在这里设置默认值更容易。这是一个例子:

%dw 2.0
output application/xml
var doctorInformationList=[{doctorId: '1'},{doctorId: '2'}, {}]
---
root: {
        DoctorInformationList: doctorInformationList map ((dValue, dIndex) -> 

        doctorId : dValue.doctorId default ""
    )
}

【讨论】:

    【解决方案2】:

    最好使用when - otherwise。 以下是针对您的问题的数据编织转换

    %dw 2.0
    %output application/json
    %var doctorInfoList=[{doctorId: '1', doctorName : 'A'},{doctorId: '2', doctorName : 'B'}, 
        {doctorId: null, doctorName : 'C'},{doctorId: '', doctorName : 'D'},{}]
    ---
    {
            DoctorInfoList: doctorInfoList map ((doctorValue, doctorIndex) -> {
                "docorId" : '' when doctorValue.doctorId is :null otherwise doctorValue.doctorId,
                "docorName" : doctorValue.doctorName 
            }
         )
    }
    

    输出如下:

    {
      "DoctorInfoList": [
        {
          "docorId": "1",
          "docorName": "A"
        },
        {
          "docorId": "2",
          "docorName": "B"
        },
        {
          "docorId": "",
          "docorName": "C"
        },
        {
          "docorId": "",
          "docorName": "D"
        },
        {
          "docorId": "",
          "docorName": null
        }
      ]
    }
    

    doctorInfoList 替换为您的payload

    【讨论】:

    • 在 DataWeave 2.0 中有...否则。您的答案混合了 DataWeave 1.0 和 2.0 语法,因此无法正常工作。
    • 在 DataWeave 2.0 中,%output%var 也是 outputvar:null 应该是 Null
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-31
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多