Class 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 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

        @Deprecated
        public StringBuilder writeToBuilder​(Bean bean)
        Deprecated.
        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

        @Deprecated
        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
      • write

        public void write​(Bean bean,
                          Appendable output)
                   throws IOException
        Writes the bean to the Appendable.

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

        Parameters:
        bean - the bean to output, not null
        output - 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 the Appendable.
        Parameters:
        bean - the bean to output, not null
        rootType - true to output the root type
        output - the output appendable, not null
        Throws:
        IOException - if an error occurs