XML to JSON conversion in REST adapter SAP PI

This blog will explain how to handle XML to JSON conversion in REST adapter. Here we will cover enhanced REST adapter settings to handle array – repeated segments.

How REST Adapter converts

REST adapter uses 3rd party Jettison library for JSON processing tasks. It is used for conversion of XML to JSON & vice-versa and sometime it does not correlate or take into consideration payload field properties as defined in a corresponding message type, but has its own optimization and type derivation mechanisms that are based on nature of the value of a processed XML document’s element rather than XSD schema of a processed message.

As a result, sometime conversion are not correct especially in case of XML element as an array.

How to handle XML to JSON conversion in REST adapter

Lets understand it by example.

Here is a DT defined in SAP PI

REST Adapter in SAP PI

If you notice Orders element can be repeated ( it’s an array). In case XML is having multiple Order nodes as shown below REST adapter conversion will happen correctly.

But if Order segment is not repeated and is only coming once ,conversion to JSON will not be correct.It will be something like below

In above JSON Order segment is not coming as array, so in this case we have to use enhanced XML/JSON conversion functionality in REST adapter to explicitly mention which field is array.

REST Adapter configuration

If we run it once again conversion to JSON will be

Reference :  SAP Note 2175218 – New Feature: Enhanced XML/JSON conversion capabilities

You may also like

https://www.techtalkzone.com/sap-pi/rest-adapter-scenario-in-sap-pi/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.