数据编织的数组输出中出现空条目
Null entry appearing in array output from dataweave
我正在使用 Anypoint Studio 7.3 和 Mule 4.2。
我正在转换一个有效负载,但我在新数组的末尾得到一个随机空值,无法弄清楚为什么在我处理此记录时它会出现。
谁能看出为什么会出现这个问题?
Dataweave 代码
%dw 2.0
output application/json
---
payload.records flatMap
((record, index) ->
records.customers flatMap ((customer, index) ->
customers.transactions flatMap ((transaction, index) ->
transaction.prices filter (!isEmpty($)) map ((price, index) ->
{
recordId: record.recordId,
customerId: customer.customerId,
transactionId: transaction.sessionId,
name: customer.name,
value: price.value
})
)
)
)
输入JSON
{
"records": [
{
"recordId": "f4f80bc7",
"customers": [
{
"customerId": "a1f773b8",
"name": "J Smith",
"transactions": [
{
"transactionId": "f610bac1"
"prices": [
{
"value": 580
},
{
"value": 8403,
},
{
"value": 8983
}
]
}
]
}
]
}
]
}
输出 JSON 随机 null
[
{
"recordId": "f4f80bc7",
"customerId": "a1f773b8",
"transationId": "f610bac1",
"name": "J Smith",
"value": 580
},
{
"recordId": "f4f80bc7",
"customerId": "a1f773b8",
"transationId": "f610bac1",
"name": "J Smith",
"value": 8403
},
{
"recordId": "f4f80bc7",
"customerId": "a1f773b8",
"transationId": "f610bac1",
"name": "J Smith",
"value": 8983
},
null
]
感谢您的帮助
您可以使用编写器 属性 skipNullOn 跳过数组中的空元素。
output application/json skipNullOn="arrays"
.
这里只是评论:使用您的 DW 脚本和输入,我无法在 Mule 4.2 中使用 null 元素重现您的输出
我正在使用 Anypoint Studio 7.3 和 Mule 4.2。
我正在转换一个有效负载,但我在新数组的末尾得到一个随机空值,无法弄清楚为什么在我处理此记录时它会出现。
谁能看出为什么会出现这个问题?
Dataweave 代码
%dw 2.0
output application/json
---
payload.records flatMap
((record, index) ->
records.customers flatMap ((customer, index) ->
customers.transactions flatMap ((transaction, index) ->
transaction.prices filter (!isEmpty($)) map ((price, index) ->
{
recordId: record.recordId,
customerId: customer.customerId,
transactionId: transaction.sessionId,
name: customer.name,
value: price.value
})
)
)
)
输入JSON
{
"records": [
{
"recordId": "f4f80bc7",
"customers": [
{
"customerId": "a1f773b8",
"name": "J Smith",
"transactions": [
{
"transactionId": "f610bac1"
"prices": [
{
"value": 580
},
{
"value": 8403,
},
{
"value": 8983
}
]
}
]
}
]
}
]
}
输出 JSON 随机 null
[
{
"recordId": "f4f80bc7",
"customerId": "a1f773b8",
"transationId": "f610bac1",
"name": "J Smith",
"value": 580
},
{
"recordId": "f4f80bc7",
"customerId": "a1f773b8",
"transationId": "f610bac1",
"name": "J Smith",
"value": 8403
},
{
"recordId": "f4f80bc7",
"customerId": "a1f773b8",
"transationId": "f610bac1",
"name": "J Smith",
"value": 8983
},
null
]
感谢您的帮助
您可以使用编写器 属性 skipNullOn 跳过数组中的空元素。
output application/json skipNullOn="arrays"
.
这里只是评论:使用您的 DW 脚本和输入,我无法在 Mule 4.2 中使用 null 元素重现您的输出