wso2 conversion, xml to json conversion

I am completely new to wso2 and I need to change my given input request xml to json and hit this to an adapter and get the response back in json and then in xml. How is this possible??

I am using wso2 integration studio for the development.

<Request>
<requestId><![CDATA[11111111111111111]]></requestId>
<timeStamp><![CDATA[2019/12/25 12:12:12]]> </timeStamp>
<msisdn> <![CDATA[888]]></msisdn>
<keyWord><![CDATA[TEST_API]]></keyWord>
<dataSet>
<param>
<id><![CDATA[first_id]]></id>
<value><![CDATA[12310209842396]]></value>
</param>
<param>
<id><![CDATA[second_id]]></id>
<value><![CDATA[1]]></value>
</param>
</dataSet>
</Request>

Upvotes: 1

Views: 467

Answers (1)

Arunan
Arunan

Reputation: 3469

In the mediation sequence, you can use the messageType property to indicate that the message should be converted to JSON when sending it to your adapter. And in the return phase, you can use the messageType property again to convert the message to XML.

<property name="messageType" value="application/json" scope="axis2"/>

Example:

<?xml version="1.0" encoding="UTF-8"?>
<api name="toJson" context="/tojson" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="POST">
        <inSequence>
            <property name="messageType" value="application/json" scope="axis2" />
            <send>
                 <endpoint key="adapter"/>   
            </send>
        </inSequence>
        <outSequence>
            <property name="messageType" value="application/xml" scope="axis2" />
            <send />
        </outSequence>
    </resource>
</api>

Upvotes: 2

Related Questions