否则数据编织映射
dataweave mapping when otherwise
`输入:-
{"id":
{
"items" : [
{
"merchant_ref": "icici",
"transaction_tag": "sdfhisdb",
"transaction_type": "balance_inquiry",
"method": "valuelink",
"order_number": "123",
"amount": "1000",
"currency_code": "CAD",
"token": {
"token_type": "",
"token_data": {
"type": "",
"value": "",
"cardholder_name": "",
"exp_date": ""
}
},
{
"merchant_ref": "icici",
"transaction_tag": "sdfhisdb",
"transaction_type": "balance_inquiry",
"method": "valuelink",
"order_number": "123",
"amount": "2000",
"currency_code": "",
"token": {
"token_type": "",
"token_data": {
"type": "",
"value": "",
"cardholder_name": "",
"exp_date": ""
}
},
{
"merchant_ref": "icici",
"transaction_tag": "sdfhisdb",
"transaction_type": "authorize",
"method": "token",
"order_number": "123",
"amount": "3000",
"currency_code": "",
"token": {
"token_type": "",
"token_data": {
"type": "",
"value": "",
"cardholder_name": "",
"exp_date": ""
}
}
]
}
}`
输出:- 没有任何 Null B,因为我需要在这个没有 Null B 的输出的基础上做另一个映射
<A>
<B>
<merchant_ref>icici</merchant_ref>
<transaction_tag>sdfhisdb</transaction_tag>
<transaction_type>balance_inquiry</transaction_type>
<method>valuelink</method>
<order_number>123</order_number>
<amount>1000</amount>
<currency_code>CAD</currency_code>
<token>
<token_type></token_type>
<token_data>
<type></type>
<value></value>
<cardholder_name></cardholder_name>
<exp_date></exp_date>
</token_data>
</token>
</B>
<B>
<merchant_ref>icici</merchant_ref>
<transaction_tag>sdfhisdb</transaction_tag>
<transaction_type>balance_inquiry</transaction_type>
<method>valuelink</method>
<order_number>123</order_number>
<amount>2000</amount>
<currency_code></currency_code>
<token>
<token_type></token_type>
<token_data>
<type></type>
<value></value>
<cardholder_name></cardholder_name>
<exp_date></exp_date>
</token_data>
</token>
</B>
</A>
尝试使用下面的数据编织检查 xml 的内容,但得到的输出为空 B,如请建议如何避免这种情况。因为我需要为每个元素做另一个从 xml 到 xml 的点对点映射,但是映射正在创建一个额外的映射,其中 B 也为 null。
请建议如何避免这种情况
%dw 1.0
%output application/xml
---
A: payload.id.*items mapObject
{
B:$ when $.method=="valuelink"
otherwise {
}
}
下面应该可以。请注意,B:$ 由 () 封装,这意味着仅当 'when' 条件为真时,才将此 属性 包含在输出中。
%dw 1.0
%output application/xml
---
{
A: payload.A.*B mapObject {
(B:$) when $.method == 'valuelink'
}
}
`输入:-
{"id":
{
"items" : [
{
"merchant_ref": "icici",
"transaction_tag": "sdfhisdb",
"transaction_type": "balance_inquiry",
"method": "valuelink",
"order_number": "123",
"amount": "1000",
"currency_code": "CAD",
"token": {
"token_type": "",
"token_data": {
"type": "",
"value": "",
"cardholder_name": "",
"exp_date": ""
}
},
{
"merchant_ref": "icici",
"transaction_tag": "sdfhisdb",
"transaction_type": "balance_inquiry",
"method": "valuelink",
"order_number": "123",
"amount": "2000",
"currency_code": "",
"token": {
"token_type": "",
"token_data": {
"type": "",
"value": "",
"cardholder_name": "",
"exp_date": ""
}
},
{
"merchant_ref": "icici",
"transaction_tag": "sdfhisdb",
"transaction_type": "authorize",
"method": "token",
"order_number": "123",
"amount": "3000",
"currency_code": "",
"token": {
"token_type": "",
"token_data": {
"type": "",
"value": "",
"cardholder_name": "",
"exp_date": ""
}
}
] } }`
输出:- 没有任何 Null B,因为我需要在这个没有 Null B 的输出的基础上做另一个映射
<A>
<B>
<merchant_ref>icici</merchant_ref>
<transaction_tag>sdfhisdb</transaction_tag>
<transaction_type>balance_inquiry</transaction_type>
<method>valuelink</method>
<order_number>123</order_number>
<amount>1000</amount>
<currency_code>CAD</currency_code>
<token>
<token_type></token_type>
<token_data>
<type></type>
<value></value>
<cardholder_name></cardholder_name>
<exp_date></exp_date>
</token_data>
</token>
</B>
<B>
<merchant_ref>icici</merchant_ref>
<transaction_tag>sdfhisdb</transaction_tag>
<transaction_type>balance_inquiry</transaction_type>
<method>valuelink</method>
<order_number>123</order_number>
<amount>2000</amount>
<currency_code></currency_code>
<token>
<token_type></token_type>
<token_data>
<type></type>
<value></value>
<cardholder_name></cardholder_name>
<exp_date></exp_date>
</token_data>
</token>
</B>
</A>
尝试使用下面的数据编织检查 xml 的内容,但得到的输出为空 B,如请建议如何避免这种情况。因为我需要为每个元素做另一个从 xml 到 xml 的点对点映射,但是映射正在创建一个额外的映射,其中 B 也为 null。
请建议如何避免这种情况
%dw 1.0
%output application/xml
---
A: payload.id.*items mapObject
{
B:$ when $.method=="valuelink"
otherwise {
}
}
下面应该可以。请注意,B:$ 由 () 封装,这意味着仅当 'when' 条件为真时,才将此 属性 包含在输出中。
%dw 1.0
%output application/xml
---
{
A: payload.A.*B mapObject {
(B:$) when $.method == 'valuelink'
}
}