Class JodaBeanXmlWriter
- java.lang.Object
-
- 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
Constructors Constructor Description JodaBeanXmlWriter(JodaBeanSer settings)
Creates an instance.JodaBeanXmlWriter(JodaBeanSer settings, StringBuilder builder)
Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description String
write(Bean bean)
Writes the bean to a string.String
write(Bean bean, boolean rootType)
Writes the bean to a string.void
write(Bean bean, boolean rootType, Appendable output)
Writes the bean to theAppendable
.void
write(Bean bean, Appendable output)
Writes the bean to theAppendable
.StringBuilder
writeToBuilder(Bean bean)
Deprecated.StringBuilder
writeToBuilder(Bean bean, boolean rootType)
Deprecated.
-
-
-
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 nullbuilder
- 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 nullrootType
- true to output the root type- Returns:
- the XML, not null
-
writeToBuilder
@Deprecated public StringBuilder writeToBuilder(Bean bean)
Deprecated.Writes the bean to theStringBuilder
.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
@Deprecated public StringBuilder writeToBuilder(Bean bean, boolean rootType)
Deprecated.Writes the bean to theStringBuilder
.- Parameters:
bean
- the bean to output, not nullrootType
- true to output the root type- Returns:
- the builder, not null
-
write
public void write(Bean bean, Appendable output) throws IOException
Writes the bean to theAppendable
.The type of the bean will be set in the message.
- Parameters:
bean
- the bean to output, not nulloutput
- the output appendable, not null- Throws:
IOException
- if an error occurs
-
write
public void write(Bean bean, boolean rootType, Appendable output) throws IOException
Writes the bean to theAppendable
.- Parameters:
bean
- the bean to output, not nullrootType
- true to output the root typeoutput
- the output appendable, not null- Throws:
IOException
- if an error occurs
-
-