Beruflich Dokumente
Kultur Dokumente
Conversion Box
v1.0
Documentation
Sr. No.
Topic
Page Number
Overview
JARs Required
Methods
Overview
The Conversion Box component works with the idea of converting data from one structure to another.
It can be used to carry out conversions between Maps, JSONs, XMLs and Java Objects. It also converts
Lists of Maps embedded within them to their corresponding equivalent. Also, the hierarchy within the
data structure is maintained.
The conversion concept is common for all scenarios. Every data structure in the input is converted to
its corresponding equivalent in the output. It can be summarized as follows:
Map
JSON
XML
Java Object
Map
JSON Object
List of Maps
JSON Array
The values of the Keys are maintained in all the conversions except for the scenarios where Lists of
Maps are involved. This can be illustrated in the following example:
Consider a Map with multiple values. Every value has its corresponding key. Lets assume this Map contains
a key that has a List of Maps mapped to it. Now we know that elements of a List do not have keys
assigned to it and their corresponding XML representations also do not necessarily need one.
However, this component works on the concept of a key for every value. Thus, it will assign a Constant
LIST_ELEMENT appended with the parent key as a key to every element of the List. This applies to all the
Lists in the input.
This applies to JSONs and Java Objects and works conversely as well. The component expects the List
representation in an XML (to be converted into a Map, JSON or Java Object) to be enclosed within a
tag for itself.
JARs required
1. JSON
2. Apache Commons BeanUtils
3. Apache Commons Logging
4. Apache Commons Collections (if required)
Methods
Class: cjm.component.cb.map.ToMap
public Map<String, Object> convertToMap(Object object)
This method will convert an Object to a Map. This Object could be a JSON, XML or a Java Object.
Class: cjm.component.cb.json.ToJSON
public JSONObject convertToJSON(Object object)
This method will convert an Object to a JSON. This Object could be a Map, XML or a Java Object.
Class: cjm.component.cb.xml.ToXML
public StringBuilder convertToXML(Object object, boolean emptyAction)
This method will convert an Object to an XML. This Object could be a Map, JSON or a Java Object.
What is emptyAction?
When there are no value to a key, the key is represented in the XML in the following two ways:
1. <KEY></KEY>
2. <KEY/>
This can be achieved by setting true to the parameter emptyAction for the first result and false
for the second.
Class: cjm.component.cb.object.ToObject
public Object convertToObject(Object object, Object objectPrimary, List<Object> objectList)
This method will convert an Object to Java Object. This Object could be a Map, JSON or an XML.
What is objectPrimary ?
When trying to convert a data structure from any form to a Java Object, the objectPrimary
parameter is the object to which the data structure is mapped to. It uses this dummy parameter to
locate members and map the appropriate values to them.
What is objectList?
When trying to convert a data structure from any form to a Java Object, the objectList parameter
is the list of objects that are nested members of the primary object to which the data is converted
to. It uses this dummy parameter to locate nested object members and map the appropriate values
to them.