javascriptnode.jsnode-soap

node-soap Including nil values in result


I'm using node-soap to connect to a SOAP API, and calling a query method which returns an array of objects with the fields specified in the request. However, the result object returned by node-soap is missing properties for records where the field has a null value, which appear in the raw response like this:

<records>
    <x:Name>ABC Limited</x:Name>
    <x:Phone xsi:nil="true"/>
    <x:Website xsi:nil="true"/>
    <x:BillingCity xsi:nil="true"/>
</records>

...and the result object would contain:

{
    "Name": "Hyatt"
}

Is there an option or something I can do with node-soap to include these in the result as properties with a null value? I was considering passing over the array of objects after and filling in the missing properties, but that seems far from ideal.


Solution

  • I just submitted a PR to node-soap to add this feature. https://github.com/vpulim/node-soap/pull/952

    If it is merged, you would just have to pass in returnNilAsNull: true in your wsdlOptions when creating your client.