Converting JSON into XML Payload for SOAP Web Service Call

Tuesday, April 17, 2018

Picture of Raman Singh
Raman Singh
Picture1_1

In this example, we will show how to use the CDATA function in the Adeptia mapper to insert XML payload into a Create Policy Quote SOAP Service. Suppose the SOAP WSDL requires complete XML payloads in three of its fields, “Spec” that contains Policy Details, “Stream” which contains Policy Header and “Action” that contains Policy function such as updated quote, new quote etc.

The three target fields would contain the Insured’s policy and the action we need to perform as part of the Create Quote Insurance service. Policy Header contains the Insured’s contact, policy number and policy data. Policy Detail contains the coverages selected for the Policy, Dependent data, Lines of Business, and the Policy Effective dates. The Policy Action requires the action we need to execute when calling this service, such as getting a Quote back from the service call as a response.

First step is to create target XML schemas for Policy Header, Policy Detail and Policy Action. This will help us to map the source JSON data to these three XML outputs. Source data is a RESTful JSON API request sent by an Insurance Comparative Rating System.

In the below map, the 3 XMLs were added as target schemas and the JSON is mapped to the related XML outputs for Policy Header, Policy Detail and Policy Action. This map produces three XML outputs that are then passed to the Create Quote SOAP as the final step in the flow.

Output of the 3 XML are inserted into three separate context variables that are then mapped to the Create Quote SOAP XML as CDATA. Mapper’s CDATA function inserts any XML payload as CDATA into the related target fields. Three context variables named are

Below is the CDATA function available in the Adeptia mapper that allows insertion of complete data payload into a target field.

For more information on how to use CDATA function, go here.

Now let’s look at the orchestration of how the incoming JSON REST request is passed to the SOAP WSDL.

This orchestration is published as a synchronous RESTful API and acts as a wrapper web service which takes the JSON from the client, maps JSON to the SOAP service, gets the response back from the SOAP service, wraps the XML response back to JSON and sends JSON response back to the clientwith the help of a SOAP to JSON converter.Here we are highlighting the part of how the JSON is mapped to three separate XML outputs which are stored in three context variables and then we are passing the context variables into the final SOAP mapping.

Summary

Converting JSON into XML is a common requirement when making SOAP web service calls. This process involves transforming JSON data into an XML payload that adheres to the SOAP structure. The goal is to ensure compatibility between systems that use different data formats.

To convert JSON to XML, specific steps need to be followed. First, the JSON data is parsed and its elements are mapped to XML tags. JSON key-value pairs are transformed into XML elements and their corresponding values. The structure of the XML payload is then built by adding the appropriate XML tags, attributes, and values.

During this conversion, it is important to consider data types, nesting levels, and any special formatting requirements of the SOAP web service. Additionally, attention should be given to handling arrays or multiple occurrences of the same element in JSON.

Converting JSON into XML for SOAP web service calls enables seamless integration between systems that communicate using different protocols. It ensures that data can be exchanged accurately and efficiently, allowing businesses to leverage the benefits of both JSON and SOAP technologies.