i’m looking for a parser or SOAP client in Java to convert XML(WSDL) from Magento SOAP v1 API to JSON Object.
Magento SOAP v1 API returns a XML which looks like this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:Magento"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:callResponse>
<callReturn xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">store_id</key>
<value xsi:type="xsd:string">1</value>
</item>
<item>
<key xsi:type="xsd:string">created_at</key>
<value xsi:type="xsd:string">2013-03-05 05:56:35</value>
</item>
<item>
<key xsi:type="xsd:string">updated_at</key>
<value xsi:type="xsd:string">2017-11-09 15:37:05</value>
</item>
<item>
<key xsi:type="xsd:string">shipping_address</key>
<value xsi:type="ns2:Map">
<item>
<key xsi:type="xsd:string">address_id</key>
<value xsi:type="xsd:string">1</value>
</item>
<item>
<key xsi:type="xsd:string">created_at</key>
<value xsi:type="xsd:string">2013-01-31 11:37:38</value>
</item>
<item>
<key xsi:type="xsd:string">updated_at</key>
<value xsi:type="xsd:string">2017-11-09 15:37:05</value>
</item>
</value>
</item>
</callReturn>
</ns1:callResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
and i would like to received a simple JSON Object like this:
{
"store_id": "1",
"created_at": "2013-03-05 05:56:35",
"updated_at": "2017-11-09 15:37:05",
"shipping_address": {
"address_id": "1",
"created_at": "2013-01-31 11:37:38",
"updated_at": "2017-11-09 15:37:05"
}
}
3
Answers
you may use this lib https://github.com/stleary/JSON-java/blob/master/src/main/java/org/json/XML.java
then parse parts of SOAP Response to get json data this way:
If you are using Java 8 or later, you should check out my open source library: unXml. unXml basically maps from Xpaths to Json-attributes.
It’s available on Maven Central.
Example
It will return a Jackson
ObjectNode
, with the following json:use