Class JavaBeanXmlSerializer

java.lang.Object
net.solarnetwork.codec.JavaBeanXmlSerializer
All Implemented Interfaces:
PropertySerializer

public class JavaBeanXmlSerializer extends Object implements PropertySerializer
PropertySerializer that serializes JavaBean objects into XML strings.

This class can also be used in a stand-alone manner, calling the public methods exposed for generating XML from JavaBean objects.

The configurable properties of this class are:

propertySerializerRegistrar
An optional registrar of PropertySerializer instances that can be used to serialize specific objects into String values. This can be useful for formatting Date objects into strings, for example.
Version:
2.0
Author:
matt
  • Constructor Details

    • JavaBeanXmlSerializer

      public JavaBeanXmlSerializer()
  • Method Details

    • serialize

      public Object serialize(Object data, String propertyName, Object propertyValue)
      Description copied from interface: PropertySerializer
      Serialize a property value.

      The data and propertyName parameters might not be used by different implementations, but allow for a single implementation to serialize more than one property of an object in different ways, if desired.

      Specified by:
      serialize in interface PropertySerializer
      Parameters:
      data - the source data being serialized, i.e. a JavaBean
      propertyName - the name of the property being serialized
      propertyValue - the value of the property to serialize
      Returns:
      the serialized value of the property
    • renderBean

      public void renderBean(Object bean, OutputStream out)
      Render a JavaBean object as XML serialized to a given OutputStream.
      Parameters:
      bean - the object to serialize as XML
      out - the OutputStream to write the XML to
    • renderMap

      public void renderMap(Map<String,?> model, OutputStream out)
      Render a Map as XML serialized to a given OutputStream.
      Parameters:
      model - the data to serialize as XML
      out - the OutputStream to write the XML to
    • parseXml

      public Map<String,Object> parseXml(InputStream in)
      Parse XML into a simple Map structure.
      Parameters:
      in - the input stream to parse
      Returns:
      a Map of the XML