public class BeanConverter extends Object
Bean2XmlConverter and
Xml2BeanConverter. If static
methods and throwaway objects offend you then use those classes directly.
Note: These conversions are intended for application-specific data transfer objects. All object access is via public getters and setters; private members are ignored. There are known issues with some JDK classes; those most likely to be used in a DTO are supported via hacks.
| Constructor and Description |
|---|
BeanConverter() |
| Modifier and Type | Method and Description |
|---|---|
static <T> T |
convertToJava(Document dom,
Class<T> klass,
Xml2BeanOptions... options)
Creates a new Java object from the root of the passed
Document
. |
static <T> T |
convertToJava(Element root,
Class<T> klass,
Xml2BeanOptions... options)
Creates a new Java object from the the passed
Element. |
static Document |
convertToXml(Object bean,
String rootName,
Bean2XmlOptions... options)
Creates a new DOM document from the passed bean, without namespace.
|
static Document |
convertToXml(Object bean,
String nsUri,
String rootName,
Bean2XmlOptions... options)
Creates a new DOM document from the passed bean, in which all elements
are members of the specified namespace and will inherit the root's
prefix (if any).
|
public static Document convertToXml(Object bean, String nsUri, String rootName, Bean2XmlOptions... options)
bean - The source object. This can be any Java object:
bean, collection, or simple type.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(Object bean, String rootName, Bean2XmlOptions... options)
bean - The source object. This can be any Java object:
bean, collection, or simple type.rootName - The name given to the root element of the produced
document.options - Conversion options.public static <T> T convertToJava(Document dom, Class<T> klass, Xml2BeanOptions... options)
Document
.dom - The source document.klass - The desired class to instantiate and fill from this
document.options - Conversion options.public static <T> T convertToJava(Element root, Class<T> klass, Xml2BeanOptions... 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.klass - The desired class to instantiate and fill from this
document.options - Conversion options.