cancel
Showing results for 
Search instead for 
Did you mean: 

Integration of JSON with SAP PI

0 Kudos

Hi Experts,

I have a query regarding whether JSON can be integrated with SAP PI without using Rest Adapter?.

I am thinking of using a Java mapping to convert JSON to xml, but however, is their any standard SAP Adapter modules for this purpose.

Let me know, whether their is any alternative to Java mapping for this.

Regards,

Roshan

Accepted Solutions (1)

Accepted Solutions (1)

MichalKrawczyk
Active Contributor
0 Kudos

Hi,

>>>I am thinking of using a Java mapping to convert JSON to xml, but however, is their any standard SAP Adapter modules for this purpose.

there are no standard module I believe but as you said you can do it in the mapping:

ABAP mapping

http://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=163840922

java:

https://github.com/tobrien/sample-json-parsing

Regards,

Michal Krawczyk

0 Kudos

  Hi Michal,

Thanks a lot for your blogs, it is very helpful indeed, I am trying the option via a Java Mapping.

However, i am getting an error as explained below:

Source code:

import java.io.InputStream;

import net.sf.json.JSON;

import net.sf.json.JSONSerializer;

import net.sf.json.xml.JSONTypes;

import net.sf.json.xml.XMLSerializer;

import org.apache.commons.io.IOUtils;

import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.Reader;

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

public class ConvertJSONtoXML {

     public static void main(String[] args) throws Exception {

            InputStream is = ConvertJSONtoXML.class.getResourceAsStream("JsonTest.txt");

           String jsonData = IOUtils.toString(is);

            XMLSerializer serializer = new XMLSerializer();

            JSON json = JSONSerializer.toJSON( jsonData );

            String xml = serializer.write( json );

            System.out.println(xml);

        }

   

    }

Error i am getting is:

java.lang.NoClassDefFoundError: nu/xom/Serializer

    at com.sap.jsontoxml.ConvertJSONtoXML.main(ConvertJSONtoXML.java:51)

Exception in thread "main"

Is it due to some compatibility issue.

I am coding in NWDS 7.0 Version.

Regards,

Roshan

Answers (2)

Answers (2)

Shabarish_Nair
Active Contributor
0 Kudos

The clean way will obviously be to use a REST adapter to simplify custom development and align yourself to a common strategy is so within your enterprise. https://www.advantco.com/product/REST

Else the best way is to use a java mapping or say a module that does the JSON to XML conversion.

A simple java code is as shown here - http://answers.oreilly.com/topic/279-how-to-convert-json-to-xml-in-java/

0 Kudos

Hi Shabarish,

Thanks for reply .

Can u tell me about the module available that does the JSON to XML conversion and vice-versa.

Regards,

Roshan

Shabarish_Nair
Active Contributor
0 Kudos

there are no standard modules available you might have to code one yourself.

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>Let me know, whether their is any alternative to Java mapping for this.

If you are using  JSON on the web application system then you can host webservice on pi soap sender and make a call to webservice from JSON.  That is one possible approach. I meant use JSON as a webservice client. Please search online for this.  I dont see standard module within PI for the conversion of json to xml.