REST adapter implements enhanced Xml/json format conversion in SAP PI

Source: Internet
Author: User

The SAP standard REST adapter has the Xml/json conversion feature, which is useful because, on the one hand, SAP PI/PO internally processes data in XML format, while on the other hand, JSON is the de facto format when dealing with the rest architectural style.

However, observing the related problems of rest adapter on the Internet, we can conclude that the JSON output generated after XML message processing is not always correct, and sometimes it can lead people astray. SAP has aggressively enhanced the various aspects of rest adapter-one of the key areas of customization and feature-rich JSON processing. Many of these features are already documented in the SAP Help documentation. But one of the fairly powerful, flexible features-called "Enhanced Xml/json Conversion"-is simply mentioned in SAP Note 2175218. In this article, I'll explain the use of this feature, as well as the details of providing an effective parameterization method.

Internally, REST adapter uses a third-party jettison to implement JSON processing. In a standard configuration, REST adapter relies on the jettison processor's default conversion logic, which does not consider or correlate the valid element attributes defined in the corresponding message type, but has its own optimization and type mechanism, based on the original nature of the values of the elements of the XML document being processed. Rather than the XSD schema of the message. As a result, sometimes the conversion results in undesirable output. Here are two general examples:

    • If an XML element is defined as an array, but contains only one row in the XML valid data being converted, the jettison processor might convert it to a non-array type.
    • If an XML element is defined as a string, but there is only a numeric value in the XML valid data being converted, the jettison processor may convert it to an integer type.

In some cases, inappropriate type conversions are unacceptable to the program-which is also an issue that enhances the Xml/json conversion to help us solve.

SAP Note 2175218 Describes an idea behind the enhanced Xml/json transformation, which is a clear description of how the JSON processor treats special XML elements. Let's test this feature based on a practice example:

The following is a definition of the message type, which is used to synchronize the return message of the scene, where we use the rest sender channel. As you can see, it contains several types of elements, including an array:

The example reply message in XML format is this:

Using the standard configuration of the rest sender channel, the JSON corresponding message after formatting the above XML message is this:

It can be noted that some element types are interpreted incorrectly, such as:

    • The element "ID" is not treated as a string, but the number--jettison processor treats it as a number because the value of the element contains only the characters of the numeric type;
    • The element "Properties" is not considered an array, and the jettison processor treats it as a non-array object in a nested structure because the spoof element contains only a child entity of "property" (no other sibling elements).

Let's fix it by enhancing the Xml/json transformation. In the rest sender channel, the parameterized information for the enhanced Xml/json conversion is stored in the table "Custom Xml/json Conversion Rules". The following are the problematic types that were highlighted previously and the configurations that did not match the transformation.

After the interface is executed again, the response message formatted as JSON is checked and the correct JSON output is now produced:

I don't see any specifics about parameterization in the official material, so let me summarize the acceptable and valid values that can be used in the enhanced Xml/json conversion, as well as explanatory notes about their use. The contents are in the following table:

Field

Describe

Valid values

XML namespaces

namespaces FOR XML elements

Prefix

XML element namespace prefix

Name

XML element name

Type

The XML element type.

The following types are currently supported:

String, Integer, Decimal, Boolean.

The symbol for the type value is not distinguished as long as it is one of the values mentioned in the valid values list.

If no value is specified, the specified Xml/json conversion directive is not applied, but the default jettison processor logic is executed.

string type

String

xs: String

xsd:string

Integer type

int

integer

Xs:integer

Xsd:integer

Decimal type

decimal

numeric

float

xs:decimal

xsd:decimal

Boolean type

bool

boolean

Xs:boolean

Xsd:boolean

xml element is an indicator of the array.

if it is an array:

1

true

Yes

if not array:

0

false

no

Default value

The value of the JSON element is assigned to the Xml/json conversion failure.

For example, in the demo given above, the value of the element "Quantity" is treated as an integer. If the original value cannot be converted to an integer (such as a letter), the JSON output gets a default value. In this case, the value is "0".

It is important to note that for default values, the system does not check element type for the type specified in "type"-it is treated as a string. In this way, for example, you can specify the default value "Invalid value" to "Quantity". The system does not prompt for errors, regardless of whether the default value and the element type (integer) do not match when the communication channel is active or when the related message is processed while the rest adapter is running. Keeping this in mind, you should be aware of the consistency of its type when setting default values.

Any value.

The following values are somewhat special:

"NULL"

(quoted) – interpreted as the string "null"

Null

(no quotation marks) – interpreted as null

“”

(only quotation marks – interpreted as an empty string

This article link: http://www.cnblogs.com/hhelibeb/p/7395567.html

English Original: REST Adapter in pi/po:enhanced Xml/json Conversion

Reference reading: PI REST Adapter–json to XML conversion,

REST adapter implements enhanced Xml/json format conversion in SAP PI

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.