Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Martin-Pankraz
Active Contributor
Dear all,

 

During my scripting journey with Cloud Platform Integration, I noticed that there are only scripting examples for groovy. This is probably due to the fact that most services in the SAP ecosystem are xml based. Also XML offers a lot of structure which is great for parsing, doing mashups, enrichment and all sorts of manipulations.

But JSON offers a similar grade of structure only with less overhead. Several benchmarks (e.g JSON-vs-XML) arrive at magnitudes of 21% overhead when it comes to XML. That impacts processing time and heap space consumption.

As promised, finally an JavaScript example for CPI that should get you up to speed. The imported classes up top make sure you can access your message headers, properties and body just like with groovy.
importClass(com.sap.gateway.ip.core.customdev.util.Message);
importClass(java.util.HashMap);
function processData(message) {
var body = String(message.getBody( new java.lang.String().getClass()));
//create json from string object
body = JSON.parse(body);

return message;
}

Especially in the OData world it makes to consider working with lightweight JSON payloads and responses. Although you can mostly ask the standard SAP OData service to answer with XML instead of JSON if you need to.

For the sake of completeness: Groovy offers a library called "JsonSlurper" that allows you to work with the JSON payload just like you typically do with XML and XmlParser or XmlSlurper.

 

Kind regards

Martin
5 Comments
Labels in this area