简体   繁体   English

Null节点的Dataweave错误

[英]Dataweave Error for Null nodes

I have done coding in dataweava as 我已经在dataweava中完成了编码

%dw 1.0
%input payload application/xml
%output application/xml skipNullOn="everywhere"
---
{((payload.*Order default []) map {
Order:{
    Channel:$.@EnterpriseCode,
    Code:$.@OrderNo,
    Status:$.@Status,
    OrderLines: {
    (($.OrderLines.*OrderLine default []) map {
    OrderLine:{
        EntryNumber:"abc",
        Status:$.@Status,

        (($.OrderStatuses.*OrderStatus default []) map {

        ShipDate:$.@StatusDate

        }) 
    }})}
}

}
)
}

But its giving error when assigning input as 但是在分配输入时给出错误

<?xml version="1.0" encoding="UTF-8"?>
<Order EnterpriseCode="111" OrderNo="222" Status="Scheduled">
    <OrderLines>
        <OrderLine PrimeLineNo="2" Status="Shipped" OrderedQty="1000">

        </OrderLine>
    </OrderLines>
</Order>

Any suggestions here? 这里有什么建议? I have tried default [] but its not working. 我尝试过default []但它不起作用。 When assigning null node its giving error. 分配null node给出错误。 I have tried filter as filter ($ != '') 我尝试过滤器作为filter ($ != '')

XML input example : XML输入示例

<?xml version="1.0" encoding="UTF-8"?>
<Order EnterpriseCode="111" OrderNo="222" Status="Scheduled">
  <OrderLines>
    <OrderLine PrimeLineNo="2" Status="Shipped" OrderedQty="1000">
       <OrderStatuses>
          <OrderStatus StatusDate="statusDate"></OrderStatus>
          <OrderStatus StatusDate="statusDate"></OrderStatus>
      </OrderStatuses>
    </OrderLine>
    <OrderLine PrimeLineNo="3" Status="Shipped3" OrderedQty="10003" ></OrderLine>
  </OrderLines>
</Order>

Note: In your example there are spaces between OrderLine open tag and close tag, you have to fix it: 注意:在您的示例中, OrderLine打开标记和关闭标记之间有空格,您必须修复它:

<OrderLine PrimeLineNo="3" Status="Shipped3" OrderedQty="10003" ></OrderLine>

Dataweave script : Dataweave脚本

%input payload application/xml
%output application/xml skipNullOn="everywhere"
---
{
  ((payload.*Order default []) map {
    Order:{
      Channel:$.@EnterpriseCode,
      Code:$.@OrderNo,
      Status:$.@Status,

      OrderLines: {
        (($.OrderLines.*OrderLine default []) map {

          OrderLine:{
            EntryNumber:"abc",
            Status:$.@Status, 

            (($.OrderStatuses.*OrderStatus default []) map ((key,pos) -> {
                ShipDate:key.@StatusDate
            }) when $!='' otherwise {})

          }

        })
      }


    }
  })
}

You can't map a value if it doesn't exist, so you have to use "when/otherwise" to verify the existence of the elements. 如果值不存在,则无法映射,因此必须使用“when / otherwise”来验证元素的存在。

Try this: This should solve your issue. 试试这个:这应该可以解决你的问题。 (Unless not/otherwise) or (when/otherwise), any combination can be used as per your requirement. (除非没有/否则)或(当/否则),可以根据您的要求使用任何组合。 "Unless not" is recommended if ShipDate is present in most cases, else replace "unless not" with "when". 如果在大多数情况下出现ShipDate,则建议“除非没有”,否则用“when”替换“除非”。

%dw 1.0
%input payload application/xml
%output application/xml skipNullOn="everywhere"
---
{
(
    (payload.*Order default []) map {
        Order: {
            Channel:$.@EnterpriseCode,
            Code:$.@OrderNo,
            Status:$.@Status,
            OrderLines: {
                (
                    ($.OrderLines.*OrderLine default []) map ({
                        OrderLine: {
                            EntryNumber:"abc",
                            Status:$.@Status,
                            (
                                ($.OrderStatuses.*OrderStatus) map {
                                    ShipDate:$.@StatusDate
                                }
                            )
                        }
                    }) unless not $.OrderLines.*OrderLine.OrderStatuses? otherwise {
                        OrderLine: {
                            EntryNumber:"abc",
                            Status:$.@Status                                
                        }
                    }
                )
            }
        }
    }
)
}

Try following approaches: 尝试以下方法:

  • use "SkipNullOn" %output application/xml skipNullOn="everywhere" 使用“SkipNullOn”%输出应用程序/ xml skipNullOn =“无处不在”
  • You can use when condition as shown below yourField: "null" when 你可以使用when下面显示的条件你的字段:“null”时

payload.yourField == null otherwise payload.yourField

Giving below the structure definition of Mule Message Object has Message Inbound Property Outbound Property Payload Variable Flow Variable Session Variable Attachment Exception Payload 给出Mule消息对象的结构定义下面有消息入站属性出站属性有效负载变量流变量会话变量附件异常有效负载

When a connector of a flow (listening on a port) receives the payload its called Inbound endpoint. 当流的连接器(侦听端口)接收到有效负载时,其称为入站端点。 When in a flow we have a connectore placed in the middle and send a payload its called Oubound endpoint. 在流程中,我们在中间放置一个连接器,并发送一个称为Oubound端点的有效负载。 Here the all the outbound properties sent to the Http Outbound flow become Inbound Properties within that flow. 此处,发送到Http Outbound流的所有出站属性都成为该流中的入站属性。

For detailed explanation see the link below. 有关详细说明,请参阅以下链接。

https://docs.mulesoft.com/mule-user-guide/v/3.8/mule-message-structure . https://docs.mulesoft.com/mule-user-guide/v/3.8/mule-message-structure

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM