Quantcast
Channel: SCN : Document List - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 571

JSONTransformBean Part 2: Converting XML to JSON content

$
0
0

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

NumberModule NameTypeModule 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/FormatConversionBeanLocal 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 NameAllowed valuesDefault valueRemarks
conversionTypeXML2JSONRequired field. Determines conversion type
converterClasscom.equalize.xpi.af.modules.json.XML2JSONConverterRequired field. Determines conversion class
indentFactorInteger values beginning from 10

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

skipRootNodeY,NNSkips root XML element in JSON output
forceArrayAllY,NNForces 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
  • pre = saves payload before conversion
  • post = saves payload after conversion
logLocationName of log version when messageLog is populated. Location defaulted to value in messageLog if logLocation not populated

 

 

Example

Module parameters

Parameter NameParameter Value
converterClasscom.equalize.xpi.af.modules.json.XML2JSONConverter
skipRootNodeY
indentFactor2

 

Result

Input

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<ns:MT_XML2JSON xmlns:ns="urn:equalize:com">

<glossary>

  <title>example glossary</title>

  <GlossDiv>

   <GlossList>

    <GlossEntry>

     <SortAs>SGML</SortAs>

     <GlossDef>

      <GlossSeeAlso>GML</GlossSeeAlso>

      <GlossSeeAlso>XML</GlossSeeAlso>

      <para>A meta-markup language, used to create markup languages such as DocBook.</para>

     </GlossDef>

     <GlossTerm>Standard Generalized Markup Language</GlossTerm>

     <GlossSee>markup</GlossSee>

     <ID>SGML</ID>

     <Acronym>SGML</Acronym>

     <Abbrev>ISO 8879:1986</Abbrev>

    </GlossEntry>

   </GlossList>

   <title>S</title>

  </GlossDiv>

</glossary>

</ns:MT_XML2JSON>

Outputout1.png

 

Screenshots of actual configuration and testing are also shown below.

 

Module configuration on an SFTP receiver channel.

param2.png

The XML input payload.

in1.png

The 'jsonContent' log version shows the JSON content after conversion. The JSON content produced is compact since parameter indentFactor was not used.

json.png

 

The audit log shows the trace of steps being executed by the module.

log.png

 

 

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!


Viewing all articles
Browse latest Browse all 571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>