Update 4 Sep 2018: Now available in CPI as well.
Update 11 Sep 2015: New parameters escapeInvalidNameStartChar and mangleInvalidNameChar to handle behavior if there are invalid characters for XML element names. Order of fields in XML output now also follows order of fields in JSON input
Update 2 Apr 2015: New parameters allowArrayAtTop and topArrayName to handle JSON Array at top level of JSON content
Update 25 Mar 2015: JSONTransformBeanBean has been refactored to be part of FormatConversionBean. Parameter conversionType replaced with converterClass. Note that some of the screenshots are not updated to reflect the new parameter converterClass
Prior to PI/PO 7.4 SP09, there is no native support for conversion of JSON to XML and vice versa. Even with SP09, JSON conversion is limited as a functionality within the new REST adapter, instead of a generic adapter module that can be used with any adapter.
In this two-part series, I will share about JSONTransformBean, a custom adapter module for handling conversion of JSON to XML and back. This module can be used in PI/PO versions older than PI/PO 7.4 SP09 and/or across different adapter types.
This first part covers JSON to XML conversion, while the second part covers XML to JSON conversion.
Refer to following blog on location of source code and/or EAR deployment file.
This module is based upon the open source JSON in Java library. In order to successfully compile and build this module, the source code for the library needs to be included. Alternatively, the compiled JAR file for the library is also included in the com.equalize.xpi.util library above.
Usage of Module in Communication Channel
Module Processing Sequence
|Number||Module Name||Type||Module Key|
<Depending on position of module in chain>
1) Asynchronous scenario,
Normally before the last module in channels
2) Synchronous scenario,
Before last module to convert request payload
After last module to convert response payload
|Custom_AF_Modules/FormatConversionBean||Local Enterprise Bean||<Any Arbitrary Value>|
Module Parameter Reference
Below are the parameters for configuration of the module for JSON to XML conversion (converterClass = ‘com.equalize.xpi.af.modules.json.JSON2XMLConverter’). Certain parameters will automatically inherit the default values if it is not configured.
|Parameter Name||Allowed values||Default value||Remarks|
PI – com.equalize.xpi.af.modules.json.JSON2XMLConverter
|Required field. Determines conversion class|
|documentName||Required field. Document name of root element of XML output|
|documentNamespace||Required field. Namespace of root element of XML output|
|indentFactor||Integer values beginning from 1||0||Determines the number of indentation spaces for each level in the XML output|
|allowArrayAtTop||Y, N||N||Determines if a JSON Array at the top level (input beginning with [) is allowed|
|topArrayName||Name of the top level JSON Array. Required field when allowArrayAtTop = ‘Y’|
First character of XML element name is validated. Character is escaped if it is not a valid name start character.
Examples: 64bit –> __64bit, $money –> __u0024money
Second and subsequent characters of XML element name are validated. Characters are mangled using the corresponding unicode number they are not valid name character.
Example: field[a] –> field__u005ba__u005d
|messageLog||pre, post||Saves a log version of the message that is viewable in Message Monitor
Available only in PI
|logLocation||Name of log version when messageLog is populated. Location defaulted to value in messageLog if logLocation not populated. Available only in PI|
|Parameter Name||Parameter Value|
Screenshots of actual configuration and testing are also shown below.
Module configuration on an SFTP sender channel.
The ‘oriJSON’ log version shows the original JSON content before conversion.
After conversion, the payload changes to XML format.
The audit log shows the trace of steps being executed by the module.
With JSONTransformBean, we are able to handle now services that provide content in JSON format.
Upcoming will be the second part of this series covering XML to JSON conversion with JSONTransformBean. Watch this space!
Second part is now out at JSONTransformBean Part 2: Converting XML to JSON content