答案 0 :(得分: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 ""
)
}
答案 1 :(得分: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