在Dataweave 2.0空白空白更换空

问题描述 投票:0回答:2

我在dataweave 2.0用空格来代替空,我试过很多的组合,但它得到错误。

截图附供您参考。

请提供相同的任何指针。

Thanks.enter image description here

mule mule-studio mule-el mule-esb mule-cluster
2个回答
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 ""
    )
}

0
投票

这是更好地使用when - otherwise。下面是dataweave变换你的问题

%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

© www.soinside.com 2019 - 2024. All rights reserved.