Class X2JConversionManager

java.lang.Object
com.x2j.converter.mgr.X2JConversionManager

public class X2JConversionManager extends Object
This class is the place where the actual logic of XML to JSON conversion resides.
It first looks out for the JSON schema. If present, the code will parse the schema and the incoming XML and then generates the output JSON as per the schema definition.
If not, the default conversion logic is applied wherein every XML node is either a JSON object or JSON Array.
For more information about the JSON schema, please visit: XML-To-JSON Converter.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the single instance of X2JConversionManager.
    org.json.JSONObject
    processJSONObject(org.json.JSONObject jsonObj, Element root)
    This method parses the JSON schema, determines that value/object that needs to be set to a particular key in the final JSON and generates the final JSON as the schema.
    It makes multiple other internal method calls to handle: JSON Object (recursive call to itself) JSON Array Strings
    org.json.JSONObject
    This method generates the output JSON based on the default conversion logic.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getInstance

      public static X2JConversionManager getInstance()
      Gets the single instance of X2JConversionManager.
      Returns:
      instance of X2JConversionManager
    • processJSONObject

      public org.json.JSONObject processJSONObject(Element root) throws X2JException
      This method generates the output JSON based on the default conversion logic.
      For more information on the conversion logic, please check the XML.toJSONObject() class here: org.json
      Parameters:
      root - the root element of the XML
      Returns:
      the resultant JSON object
      Throws:
      X2JException - if any error is thrown during default conversion process
    • processJSONObject

      public org.json.JSONObject processJSONObject(org.json.JSONObject jsonObj, Element root) throws X2JException
      This method parses the JSON schema, determines that value/object that needs to be set to a particular key in the final JSON and generates the final JSON as the schema.
      It makes multiple other internal method calls to handle:
      1. JSON Object (recursive call to itself)
      2. JSON Array
      3. Strings
      Parameters:
      jsonObj - the JSON schema
      root - the root element of the XML
      Returns:
      the resultant JSON object
      Throws:
      X2JException - if any error is thrown during the conversion process