org.joda.beans.ser.xml
Class JodaBeanXmlWriter

java.lang.Object
  extended by org.joda.beans.ser.xml.JodaBeanXmlWriter

public class JodaBeanXmlWriter
extends Object

Provides the ability for a Joda-Bean to be written to XML.

This class contains mutable state and cannot be used from multiple threads. A new instance must be created for each message.

The XML consists of a root level 'bean' element with a 'type' attribute. At each subsequent level, a bean is output using the property name. Where necessary, the 'type' attribute is used to clarify a type.

Simple types, defined by Joda-Convert, are output as strings. Beans are output recursively within the parent property element. Collections are output using 'item' elements within the property element. The 'item' elements will use 'key' for map keys, 'count' for multiset counts and 'null=true' for null entries. Note that map keys must be simple types.

If a collection contains a collection then more information is written. A 'metatype' attribute is added to define the high level type, such as List. At this level, the data read back may not be identical to that written.

Type names are shortened by the package of the root type if possible. Certain basic types are also handled, such as String, Integer, File and URI.


Constructor Summary
JodaBeanXmlWriter(JodaBeanSer settings)
          Creates an instance.
JodaBeanXmlWriter(JodaBeanSer settings, StringBuilder builder)
          Creates an instance.
 
Method Summary
 String write(Bean bean)
          Writes the bean to a string.
 String write(Bean bean, boolean rootType)
          Writes the bean to a string.
 StringBuilder writeToBuilder(Bean bean)
          Writes the bean to the StringBuilder.
 StringBuilder writeToBuilder(Bean bean, boolean rootType)
          Writes the bean to the StringBuilder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JodaBeanXmlWriter

public JodaBeanXmlWriter(JodaBeanSer settings)
Creates an instance.

Parameters:
settings - the settings to use, not null

JodaBeanXmlWriter

public JodaBeanXmlWriter(JodaBeanSer settings,
                         StringBuilder builder)
Creates an instance.

Parameters:
settings - the settings to use, not null
builder - the builder to output to, not null
Method Detail

write

public String write(Bean bean)
Writes the bean to a string.

The type of the bean will be set in the message.

Parameters:
bean - the bean to output, not null
Returns:
the XML, not null

write

public String write(Bean bean,
                    boolean rootType)
Writes the bean to a string.

Parameters:
bean - the bean to output, not null
rootType - true to output the root type
Returns:
the XML, not null

writeToBuilder

public StringBuilder writeToBuilder(Bean bean)
Writes the bean to the StringBuilder.

The type of the bean will be set in the message.

Parameters:
bean - the bean to output, not null
Returns:
the builder, not null

writeToBuilder

public StringBuilder writeToBuilder(Bean bean,
                                    boolean rootType)
Writes the bean to the StringBuilder.

Parameters:
bean - the bean to output, not null
rootType - true to output the root type
Returns:
the builder, not null


Copyright © 2007–2015 Joda.org. All rights reserved.