Quantcast
Channel: SCN : All Content - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 7030

JAVA Mapping for XML conversion during runtime

$
0
0

Dear SAP JAVA experts,

 

 

For quite I have been struggling to keep the JAVA code in place for JSON to XML conversion being a newbie.

 

Following is the code snippet.

 

 

import java.io.InputStream;

import net.sf.json.JSON;

import net.sf.json.JSONSerializer;

import net.sf.json.xml.XMLSerializer;

import org.apache.commons.io.IOUtils;

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;

 

import com.sap.aii.utilxi.core.io.IOUtil;

 

 

public class RuntimeJSONtoXML extends AbstractTransformation {

 

  public void transform(TransformationInput input, TransformationOutput output)

  throws StreamTransformationException {

 

  try

 

    {

 

//InputStream is = JSONtoXML.class.getResourceAsStream("JSON.txt");

 

   String strJSON = "";

   InputStream inputStream = input.getInputPayload().getInputStream();

   inputStream.close();

   String jsonData = IOUtils.toString(strJSON);

           XMLSerializer serializer = new XMLSerializer();

           JSON json = JSONSerializer.toJSON( jsonData );

           String xml = serializer.write( json );

 

           //System.out.println(xml);

 

           output.getOutputPayload().getOutputStream().write(strJSON.getBytes());

     }

 

  catch(Exception ie) { }

 

  }

 

  }

 

Caught unaware of 2 queries.

 

1.I have added the com.sap.aii.utilxi.core.io.IOUtil jar files from the PI server even though its displays error "The com.sap.aii.utilxi can not be resolved". Also I added the XPI libraries in NWDS but nothing moving to solve the issue.

 

 

2. I have commented the line of code where I have placed a test file in the path to test it i.e. JSON.text. But when it is deployed as Archived files, then this code has to be replaced.

 

The Method toString(InputStream) in the type IOUtils is not applicable for the arguments (String)

Regards

Rebecca..


Viewing all articles
Browse latest Browse all 7030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>