on 07-23-2012 12:14 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.