Dataweave字段名为“zip”我如何在映射中使用它?

时间:2016-07-15 21:00:31

标签: mule dataweave

我正在收到有效载荷:

{
  "street": "123 fake st",
  "city": "San Francisco"
  "state": "CA",
  "zip": 94117
}

但是在我的数据编织中,看起来编辑认为zip是一个函数。我怎么认为不这么想?这是我的数据编织:

Address: {
        Street: payload.address.street,
        City: payload.address.city,
        State: payload.address.state,
        Zip: payload.address.zip
    },

列出的错误位于“Zip:payload.address。 zip

感谢您的帮助

2 个答案:

答案 0 :(得分:1)

如Anirban所述,该配置正常运行。实际上,当我们在Studio中打开DataWeave代码时, zip 字段被识别为函数。 Studio将其列为错误。

因此,为避免歧义,我建议将其包装在单引号内:Zip: payload.address.'zip'。没有列出任何错误。

答案 1 :(得分:0)

我发现以下示例有效:

 <flow name="application1Flow">
         <http:listener config-ref="HTTP_Listener_Configuration" path="/test" doc:name="HTTP"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:input-payload doc:sample="json.json"/>
            <dw:set-payload><![CDATA[%dw 1.0
%input payload application/json
%output application/json
---
Address:{
    Street: payload.address.street,
    City: payload.address.city,
    State: payload.address.state,
    Zip: payload.address.zip

    }]]></dw:set-payload>
        </dw:transform-message>
        <logger message="Payload #[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
</flow>

我使用的输入请求是: -

{

"address": {
    "street": "123 fake st",
    "city": "San Francisco",
    "state": "CA",
    "zip": 94117
}

}

我发现它有效: - enter image description here