public class JsonConverter extends Object
package docs for
details.
This class provides static facade methods for
Json2XmlConverter and
Xml2JsonConverter. If static
methods and throwaway objects offend you then use those classes directly.
| Constructor and Description |
|---|
JsonConverter() |
| Modifier and Type | Method and Description |
|---|---|
static String |
convertToJson(Document dom,
Xml2JsonOptions... options)
Creates a new JSON string from the root of the passed
Document
. |
static StringBuilder |
convertToJson(Element root,
StringBuilder buf,
Xml2JsonOptions... options)
Creates a new JSON string from the the passed
Element, and
appends that string to the passed buffer (the buffer is actually passed
into the JSON construction code). |
static String |
convertToJson(Element root,
Xml2JsonOptions... options)
Creates a new JSON string from the the passed
Element. |
static void |
convertToXml(String json,
Element parent,
Json2XmlOptions... options)
Converts the passed JSON string to XML, appended as children of the
passed element.
|
static Document |
convertToXml(String json,
String rootName,
Json2XmlOptions... options)
Creates a new DOM document from the passed bean, without namespace.
|
static Document |
convertToXml(String json,
String nsUri,
String rootName,
Json2XmlOptions... options)
Creates a new DOM document from the passed JSON string, in which all
elements are members of the specified namespace and will inherit the
root's prefix (if any).
|
public static Document convertToXml(String json, String nsUri, String rootName, Json2XmlOptions... options)
json - The source object.nsUri - The namespace of the root element. This will be
inherited by all child elements.rootName - The qualified name given to the root element of the
generated document. If a qualified name, all child
elements will inherit its prefix.options - Conversion options.public static Document convertToXml(String json, String rootName, Json2XmlOptions... options)
json - The source object.rootName - The name given to the root element of the produced
document.options - Conversion options.public static void convertToXml(String json, Element parent, Json2XmlOptions... options)
json - The source object.parent - The parent elementoptions - Conversion options.public static String convertToJson(Document dom, Xml2JsonOptions... options)
Document
.dom - The source document.options - Conversion options.public static String convertToJson(Element root, Xml2JsonOptions... options)
Element.
This is useful when a DOM contains a tree of objects and you just
want to convert one of them.root - The source element -- this may or may not be the
root element of its document.options - Conversion options.public static StringBuilder convertToJson(Element root, StringBuilder buf, Xml2JsonOptions... options)
Element, and
appends that string to the passed buffer (the buffer is actually passed
into the JSON construction code).root - The source element -- this may or may not be the
root element of its document.buf - A buffer to which the JSON is appended.options - Conversion options.