JSONUtils
Class FQN: it.greenvulcano.util.json.JSONUtils
Following the JSONUtils public static methods
- Parsing & Conversion
/**
* Convert the input XML to a JSONObject.
* JSON does not distinguish between elements and attributes.
* Sequences of similar elements are represented as JSONArrays.
* If an element have attributes, content text/cdata may be placed in a "contentText" member.
* Comments and namespaces are ignored.
* If the root element is 'DEFAULT_ROOT' then isn't included into JSON output.
*
* @param xml
* the document to convert
* @return a JSONObject representing the JSON document
* @throws JSONUtilsException when error occurs
*/
public static JSONObject xmlToJson(Object xml) throws JSONUtilsException
/**
* Convert the input XML to a JSONObject.
* JSON does not distinguish between elements and attributes.
* Sequences of similar elements (or elements which local-name are in forceElementsArray)
* are represented as JSONArrays.
* If an element have attributes, content text/cdata may be placed in a "contentText" member.
* Comments and namespaces are ignored.
* If the root element is 'DEFAULT_ROOT' then isn't included into JSON output.
*
* @param xml
* the document to convert
* @param forceElementsArray
* a set containing element's local-name to be forced as JSONArray also if in single instance
* @param forceStringValue
* a set containing element's local-name to be forced as String values, ignoring type conversions
* @return a JSONObject representing the XML document
* @throws JSONUtilsException
*/
public static JSONObject xmlToJson(Object xml, Set<String> forceElementsArray, Set<String> forceStringValue) throws JSONUtilsException
/**
* Convert a JSONObject into an XML structure.
* If the JSON to be converted doesn't have a single root element
* then is automatically created a 'DEFAULT_ROOT' root element.
*
* @param json
* a JSONObject
* @return a Node representing the JSON document
* @throws JSONException
*/
public static Node jsonToXml(Object json) throws JSONUtilsException
/**
* Convert a JSONObject into an XML structure.
* If the JSON to be converted doesn't have a single root element
* then is automatically created a 'DEFAULT_ROOT' root element.
*
* @param json
* a JSONObject
* @param forceAttribute
* a set containing keys name to be set as XML attributes
* @return a Node representing the JSON document
* @throws JSONException
*/
public static Node jsonToXml(Object json, Set<String> forceAttributes) throws JSONUtilsException
/**
* Convert a JSONObject into Node structure.
* If not specified a rootName and the JSON to be converted doesn't have
* a single root element then is automatically created a 'DEFAULT_ROOT' root element.
*
* @param json
* a JSONObject
* @param rootName
* the optional name of the root element
* @return a Node representing the JSON document
* @throws JSONUtilsException
*/
public static Node jsonToXml(Object json, String rootName) throws JSONUtilsException
/**
* Convert a JSONObject into Node structure.
* If not specified a rootName and the JSON to be converted doesn't have
* a single root element then is automatically created a 'DEFAULT_ROOT' root element.
*
* @param json
* a JSONObject
* @param rootName
* the optional name of the root element
* @param forceAttributes
* a set containing keys name to be set as XML attributes
* @return a Node representing the JSON document
* @throws JSONUtilsException
*/
public static Node jsonToXml(Object json, String rootName, Set<String> forceAttributes) throws JSONUtilsException
/**
* Convert the input XML to a JSONObject using BadgerFish convention.
* See <a href="http://badgerfish.ning.com">http://badgerfish.ning.com</a>
*
* @param xml
* the document to convert
* @return a JSONObject representing the XML document
* @throws JSONUtilsException
*/
public static JSONObject xmlToJson_BadgerFish(Object xml) throws JSONUtilsException
/**
* Convert a JSONObject in BadgerFish notation into Node structure.
* See <a href="http://badgerfish.ning.com">http://badgerfish.ning.com</a>
*
* @param json
* a JSONObject
* @return a Node representing the JSON document
* @throws JSONUtilsException
*/
public static Node jsonToXml_BadgerFish(Object json) throws JSONUtilsException