Update 31 Mar 2016: Enhancement to support forcing of JSON output in arrays irrespective of number of values in payload with new parameters forceArrayAll or arrayFieldList
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
Introduction
This is the second part of the two-part series on conversion of JSON content with a custom adapter module. The first part covered the conversion of JSON to XML at a sender channel.
This second part will focus on conversion of XML to JSON at a receiver channel.
Source Code
Refer to following blog on location of source code and/or EAR deployment file.
FormatConversionBean - One Bean to rule them all!
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 XML to JSON conversion (converterClass = 'com.equalize.xpi.af.modules.json.XML2JSONConverter'). Certain parameters will automatically inherit the default values if it is not configured.
Parameter Name | Allowed values | Default value | Remarks |
---|---|---|---|
conversionType | XML2JSON | Required field. Determines conversion type | |
converterClass | com.equalize.xpi.af.modules.json.XML2JSONConverter | Required field. Determines conversion class | |
indentFactor | Integer values beginning from 1 | 0 | Determines the number of indentation spaces for each level in the JSON output. Note: When indentation is not used, the JSON content produced is compact and ideal for lightweight data transfer |
skipRootNode | Y,N | N | Skips root XML element in JSON output |
forceArrayAll | Y,N | N | Forces all nodes and fields to be in JSON Array |
arrayFieldList | Comma separated values of field names to be forced as JSON Array. Example: field1,field2,field3 | ||
messageLog | pre, post | Saves a log version of the message that is viewable in Message Monitor
| |
logLocation | Name of log version when messageLog is populated. Location defaulted to value in messageLog if logLocation not populated |
Example
Module parameters
Parameter Name | Parameter Value |
---|---|
converterClass | com.equalize.xpi.af.modules.json.XML2JSONConverter |
skipRootNode | Y |
indentFactor | 2 |
Result
Screenshots of actual configuration and testing are also shown below.
Module configuration on an SFTP receiver channel.
The XML input payload.
The 'jsonContent' log version shows the JSON content after conversion. The JSON content produced is compact since parameter indentFactor was not used.
The audit log shows the trace of steps being executed by the module.
Conclusion
With the completion of this second part for JSONTransformBean, we now have a generic and reusable custom adapter module that is able to handle conversion of JSON to XML and vice versa! Bring on the RESTful web services!