简体   繁体   中英

dataweave 1.0 to 2.0 migration in mule

Trying to convert the below dataweave from 1.0 to 2.0 , but everything I've tried gives the following errors like

SkipNullon shows error

Usage of Namespacing is not accepted,

@PostalCode[0..4] is not valid and

can't access the value inside insuredInfo using insuredPrimaryAddr.

Dataweave 1.0:

%dw 1.0
%output application/xml skipNullOn="everywhere"
%var insuredInfo = payload.DTOApplication.DTOInsured
%var insuredPrimaryAddr = insuredInfo.*PartyInfo[?($.@PartyTypeCd == "InsuredParty")].*Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0]
%namespace ns0 http://decisionresearch.com/RateMaker
---
ns0#rate:{
    ns0#code:insuredPrimaryAddr,
    ns0#ZipCode: payload..Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0].@PostalCode[0..4] default ""
}

I tried Dataweave 2.0:

%dw 2.0
output application/xml skipNullOn="everywhere"
var insuredInfo = payload.DTOApplication.DTOInsured
var insuredPrimaryAddr = insuredInfo.*PartyInfo[?($.@PartyTypeCd == "InsuredParty")].*Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0]
namespace ns0 http://decisionresearch.com/RateMaker
---
ns0#rate:{
    ns0#code:insuredPrimaryAddr,
    ns0#ZipCode: payload..Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0].@PostalCode[0..4] default ""
}

payload: https://github.com/Manikandan99/rate-dtostep/blob/master/response.xml

Any ideas please on how to write the same in dataweave 2.0?

In dataweave 2.0 we use to operator for array indexing.

%dw 2.0
output application/xml skipNullOn="everywhere"
var insuredInfo = payload.DTOApplication.DTOInsured
var insuredPrimaryAddr = insuredInfo.*PartyInfo[?($.@PartyTypeCd == "InsuredParty")].*Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0]
ns ns0 http://decisionresearch.com/RateMaker
---
ns0#rate:{
    ns0#code:insuredPrimaryAddr,
    ns0#ZipCode: payload..Addr[?($.@AddrTypeCd == "InsuredPrimaryBusAddr")][0].@PostalCode[0 to 4] default ""
}

Output

<?xml version='1.0' encoding='windows-1252'?>
<ns0:rate xmlns:ns0="http://decisionresearch.com/RateMaker">
  <ns0:ZipCode>80003</ns0:ZipCode>
</ns0:rate>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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