Force correct format for XML/JSON conversion in SAP PI

I encountered something a bit annoying recently with the SAP PI REST adapter and I just wanted to share.

So I was working on a scenario where we were sending data to an external applications thru a BUS.

We are using REST to communicate with the Bus and as you probably know SAP PI works mostly with XML. So sending the data involves a necessary transformation to JSON.

Luckily SAP’s REST adapter also include a feature to provide XML/JSON conversion.

However after several tests I noticed that the JSON created was not how we were expecting.

I tried looking up on the net here and there but information on the generation of JSON output a processed XML message payload was not really clear.

To give an exemple a string field that only contains a numeric value will automatically be converted into a number. I can see how it could make sense but in some cases it is a behaviour that you do not want.

Looking around for a solution I found this good blog post ( https://community.sap.com/t5/technology-blogs-by-members/rest-adapter-in-pi-po-enhanced-xml-json-conversion/ba-p/13197983 ) by Vadim who already saved a lot of time before on some CPI / Groovy related subjects before.

I learned that SAP was using a third party processor for JSON called Jettison ( https://github.com/jettison-json/jettison). All the weird stuff I was seeing in my tests were actually the default behaviour for Jettison.

Not having control on Jettinson, SAP introduced an enhanced XML/JSON conversion parameterization feature to give more flexibility on the conversion.

You can specify the format you want to force the field in.

It is available in the General Tab of the REST sender channel. You have a table called Custom XML/JSON Conversion Rules.

I let you check Vadim’s blog for more details but using this table is how I fixed all my JSON formatting issues.

If you have the same issues I definitely recommend to checkout Vadim’s post.

Leave a comment