Input
<?xml version='1.0' encoding='UTF-8'?>
<Requests
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<RequestBase type="AccountMaintenanceRequest">
<Accounts
xmlns:d8p1="http://schemas.datacontract.org/2004/07/OpenSolutions.CoreApiService.Services.Messages">
<d8p1:PropertyTax>
<d8p1:CalendarPeriodCode xsi:nil="true"/>
<d8p1:TaxOrganizationNumber xsi:nil="true">31072</d8p1:TaxOrganizationNumber>
<d8p1:AcctPropTaxDetails xsi:nil="true"/>
</d8p1:PropertyTax>
</Accounts>
</RequestBase>
</Requests>
DW without writeNilOnNull=true
%dw 2.0
output application/xml
ns s http://schemas.xmlsoap.org/soap/envelope/
ns i http://www.w3.org/2001/XMLSchema-instance
ns d6p1 http://schemas.microsoft.com/2003/10/Serialization/Arrays
---
s#Envelope: {
s#Header: '',
s#Body: {
SubmitRequest @(xmlns: "http://www.opensolutions.com/CoreApi"): {
'input' @("xmlns:i": i): {
Input: {
ExtensionRequests @("xmlns:d6p1": d6p1): '',
Requests : {
RequestBase @("i:type": payload.Requests.RequestBase.@'type'): payload.Requests.RequestBase
}
}
}
}
}
}
Output without writeNilOnNull=true
<?xml version='1.0' encoding='UTF-8'?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header/>
<s:Body>
<SubmitRequest xmlns="http://www.opensolutions.com/CoreApi">
<input xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Input>
<ExtensionRequests xmlns:d6p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
<Requests>
<RequestBase i:type="AccountMaintenanceRequest">
<Accounts>
<d8p1:PropertyTax xmlns:d8p1="http://schemas.datacontract.org/2004/07/OpenSolutions.CoreApiService.Services.Messages">
<d8p1:CalendarPeriodCode/>
<d8p1:TaxOrganizationNumber/>
<d8p1:AcctPropTaxDetails/>
</d8p1:PropertyTax>
</Accounts>
</RequestBase>
</Requests>
</Input>
</input>
</SubmitRequest>
</s:Body>
</s:Envelope>
Here in the above scenario, null attributes has been removed from CalendarPeriodCode , TaxOrganizationNumber and AcctPropTaxDetails. Also the value of TaxOrganizationNumber is also lost
Output with writeNilOnNull=true
<?xml version='1.0' encoding='UTF-8'?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header/>
<s:Body>
<SubmitRequest xmlns="http://www.opensolutions.com/CoreApi">
<input xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Input>
<ExtensionRequests xmlns:d6p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
<Requests>
<RequestBase i:type="AccountMaintenanceRequest">
<Accounts>
<d8p1:PropertyTax xmlns:d8p1="http://schemas.datacontract.org/2004/07/OpenSolutions.CoreApiService.Services.Messages">
<d8p1:CalendarPeriodCode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<d8p1:TaxOrganizationNumber xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<d8p1:AcctPropTaxDetails xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</d8p1:PropertyTax>
</Accounts>
</RequestBase>
</Requests>
</Input>
</input>
</SubmitRequest>
</s:Body>
</s:Envelope>
Here in the above scenario, null attributes is there for all fields along with xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
namespace. But still the value of TaxOrganizationNumber is lost.
Expected Output
<?xml version='1.0' encoding='UTF-8'?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header/>
<s:Body>
<SubmitRequest xmlns="http://www.opensolutions.com/CoreApi">
<input xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Input>
<ExtensionRequests xmlns:d6p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
<Requests>
<RequestBase i:type="AccountMaintenanceRequest">
<Accounts>
<d8p1:PropertyTax>
<d8p1:CalendarPeriodCode xsi:nil="true"/>
<d8p1:TaxOrganizationNumber xsi:nil="true">36712</d8p1:TaxOrganizationNumber>
<d8p1:AcctPropTaxDetails xsi:nil="true"/>
</d8p1:PropertyTax>
</Accounts>
</RequestBase>
</Requests>
</Input>
</input>
</SubmitRequest>
</s:Body>
</s:Envelope>
Maybe Input is incorrect due to nil=true but that is the data which we receive.
- Is it possible to keep the original Input fields as it is after mapping without any attribute or values getting removed?
- If the above is not possible then with using
writeNilOnNull=true
is it possible to retain the values atleast?
Since original data is bigger, dynamic solution will help