See: Description
Class | Description |
---|---|
Bean2XmlAppenders |
Packaging class used for XML output appenders.
|
Bean2XmlAppenders.Appender |
An
Appender appends children to a single node of the output
tree. |
Bean2XmlAppenders.BasicAppender |
Basic appender, which appends new elements to a parent element.
|
Bean2XmlAppenders.DirectAppender |
An appender that sets values directly on the passed element.
|
Bean2XmlAppenders.IndexedAppender |
Appender for children of an indexed/iterated item (array, list, or set).
|
Bean2XmlAppenders.MapAppender |
Appender for children of a
Map . |
Bean2XmlConverter |
Driver class for converting a Java bean into an XML DOM.
|
Introspection | Deprecated
This class is now contained in the KDGCommons library; all future
enhancements or bugfixes will be made to that version.
|
IntrospectionCache | Deprecated
This class is now contained in the KDGCommons library; all future
enhancements or bugfixes will be made to that version.
|
Xml2BeanConverter |
Driver class for converting an XML DOM into a Java bean.
|
Enum | Description |
---|---|
Bean2XmlOptions |
Options used by
Bean2XmlConverter to control the structure of the
generated DOM tree. |
Xml2BeanOptions |
Options used by
Xml2BeanConverter to control the way that DOM trees
are translated to Java beans. |
On output, the caller may specify a namespace: all elements will have this
namespace. On input, namespaces are ignored: bean properties are identified
by element local names. The converter will use its own namespace for any
converter-specific attributes (eg, type
); this namespace is
defined by net.sf.practicalxml.converter.internal.ConversionStrings#NS_CONVERSION
). The converter will also apply attributes from the XML Schema Instance
namespace; all documentation refers to these attributes with an "xsi" prefix
(eg: xsi:nil
).
The most important of the converter-specific attributes is type
.
For primitive types, wrappers, and strings, it takes the form
"xsd:TYPE
", where TYPE
is one of the simple types
defined by XML schema. For other Java types, it takes the form
"java:TYPE
", where TYPE
is the fully qualified
Java classname.
On input, the desired type is specified by the caller or by introspection.
The type
attribute, if any, is used to validate whether the
element matches this desired type (except in the case of collection elements,
described below).
Additional conversion rules are as follows:
Java Object Type | Java to XML | XML to Java |
---|---|---|
Null Values | By default, any field containing a null value is ignored and not written to the output. | By default, any element that does not contain a Text child is treated
as null , and ignored (because bean fields should already
be null at construction). Optionally requires an xsi:nil
attribute for values that are legally null, and throws if an empty
element appears without it.
|
Primitives, Wrapper objects, and String | By default, calls toString() on the object; optionally
uses a Schema-compliant formatter (only applies to dates and floating
point numbers).
| Uses the built-in parsers for the destination type, except where instructed to use Schema-compliant parsing. |
Enums | Uses the enum's name, as returned by name() .
| Uses the enum's valueOf method.
|
Arrays | By default, arrays are converted using one "container" element to
represent the array, and multiple children of that container to
represent the elements in the array. The container element is named
after the field being converted. By default, the child elements are
named "data", but optionally may be named after the field or a
depluralized version of the field (eg, if the field is named "widgets"
the child elements may be named "widgets" or "widget" depending on
options).
An alternate option is to output the array's elements directly, as repeated elements named after the field, without a "container" element (eg, if a bean has a field named "widgets" with 3 elements, then the XML produced from that bean will have three Elements named "widgets", each of which contains the data from the corresponding array element). Elements may also be given an "index" attribute, holding their index within the array (numbered from 0). This attribute is not output by default, as its chief use is self-documenting data. | The DOM must have a "container" element; the children of this element become the elements of the array. The names of the children are ignored, as is any "index" attribute. The children are converted according to the base element type of the array. |
Lists and Sets | The collection is written as if it were an array (qv). Child elements are output in iterator order. | The collection is processed as it if were an array (qv), with one (major)
difference: since all collections inherently contain Objects, there is no
type information to drive conversion. If a type attribute is
present, it will be used to drive conversion. Otherwise, the element will
be converted as a String (which will fail for complex types,
because string conversion assumes a single text node).
Where the caller specifies an interface as the conversion class, the converter will choose an appropriate implementation class:
|
Maps | The map itself is represented by a "container" element, which holds one
child per map entry. The map's entry-set is iterated, and children are
emitted in the order of this iteration.
By default, child elements have the name " | The converter expects a "container" element with one child per map
entry. Elements are processed in sequence, which means that later
elements with the same key value will overwrite earlier elements.
When processing an element, the converter first looks for an attribute
named "
If the Where the caller specifies an interface as the conversion class, the converter will choose an appropriate implementation class:
|
Bean-structured Objects | The object is introspected, and properties are written in the order provided by the introspector. Note that this means you can't validate beans against a schema, as the order of elements may change. | The bean class must provide a no-argument constructor (otherwise it
doesn't follow the bean spec, and we can't use it).
The converter relies on Elements are processed in order, and the element's localname is used to find the associated object property. If the XML does not contain an element corresponding to a bean property, that property is left with its default value (ie, we don't try to find an element based on property name). If the XML contains an element that does not correspond to any bean property, the converter will either throw or ignore the element, depending on options settings. |
Other Objects | not supported | not supported |