Mulesoft Dataweave 表达式抛出错误

Mulesoft Dataweave expression throwing an error

Check image to view mule4 screen 我正在使用 mule4 构建集成流,使用 Dataweave 表达式进行数据转换,使用邮递员测试 HTTP 调用,我正在尝试从下面的 Dataweave 中的 XML 获取 0011x000014VegoAAC 并插入到 Salesforce 记录中 一切正常,直到我添加这两行(它们应该从 XML 中提取 0011x000014VegoAAC)

PBSI__Customer__c: (payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute") 
    filter (item) -> (item.@"attribute-id" == "sscAccountid") 

XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order order-no="00000907" xmlns="http://www.demandware.com/xml/impex/order/2006-10-31">
    <order-date>2020-07-10T08:57:05.076Z</order-date>
    <current-order-no>00000907</current-order-no>
    <product-lineitems>
        <product-lineitem>
            <net-price>54.17</net-price>
        </product-lineitem>
    </product-lineitems>
    <custom-attributes>
        <custom-attribute attribute-id="Adyen_pspReference">852594371442812G</custom-attribute>
        <custom-attribute attribute-id="Adyen_value">7099</custom-attribute>
        <custom-attribute attribute-id="sscAccountid">0011x000014VegoAAC</custom-attribute>
    </custom-attributes>
</order>

完整的 Dataweave 代码

 %dw 2.0
    output application/java
    ns ns0 http://www.demandware.com/xml/impex/order/2006-10-31
    ---
    [{  
        Ascent4Ecomm__Ecomm_Order_ID__c: payload.ns0#order.ns0#"original-order-no",
        Ascent4Ecomm__Ecomm_Order_Name__c: payload.ns0#order.ns0#"original-order-no",
        Ascent4Ecomm__Ecomm_Order_Number__c: payload.ns0#order.ns0#"original-order-no", 
        attributes: {
            "type": "PBSI__PBSI_Sales_Order__c",
            "referenceId": "SO"
        },
        PBSI__Sales_Order_Lines__r: {
            records: payload.ns0#order.ns0#"product-lineitems".*ns0#"product-lineitem" map ( e , empindex ) -> {
                "attributes": {
                    "type": "PBSI__PBSI_Sales_Order_Line__c",
                    "referenceId": e.ns0#"product-id"
                },
                "PBSI__Item__c": e.ns0#"custom-attributes".ns0#"custom-attribute",
                "PBSI__ItemDescription__c": e.ns0#"product-name"
            }
        },
***These two lines throws error:***
        PBSI__Customer__c: (payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute")
            filter (item) -> (item.@"attribute-id" == "sscAccountid")
    }]

错误

:Invalid status code: 400, response body: [{"message":"Cannot deserialize instance of reference from START_ARRAY value [line:1, column:423]","errorCode":"JSON_PARSER_ERROR"}]

在那两行之前一切正常[Mule4 屏幕][2]

我正在使用邮递员对该流进行 HTTP 调用

这是 HTTP 400 错误。该描述表明某些应用程序正在尝试解析 JSON 输入。目前还不清楚与您的 DataWeave 转换的关系,但它正在输出 Java,而不是 JSON。可能您需要将输出更改为 application/JSON。

更新:根据评论,你从 PBSI__Customer__c 到 return 一个带有一些 id 的字符串,它是 return 问题中 DataWeave 表达式的列表,你需要得到第一个元素。您可以使用索引选择器 [0] 获得它,但我不知道是否可以保证有效载荷始终只有一个元素。

PBSI__Customer__c: ((payload.ns0#order.ns0#"custom-attributes".*ns0#"custom-attribute")
        filter (item) -> (item.@"attribute-id" == "sscAccountid")) [0]