Class XmlSerializer

java.lang.Object
org.rapidcontext.core.data.XmlSerializer

public final class XmlSerializer extends Object
A data serializer for XML. It will read and write stand-alone XML documents in the UTF-8 character set. The following basic requirements must be met in order to serialize an object:
  • No circular references are permitted.
  • String, Integer, Boolean, Date, Array and Dict values are supported.
  • Other value types are converted to strings.
  • Key names should consist of valid XML tag characters (or will be transformed).
Version:
1.0
  • Field Details

  • Method Details

    • serialize

      public static void serialize(Object obj, OutputStream os) throws IOException
      Serializes an object into an XML representation.
      Parameters:
      obj - the object to convert, or null
      os - the output stream to write to
      Throws:
      IOException - if the data couldn't be serialized
    • serialize

      public static String serialize(String id, Object obj)
      Serializes an object into an XML representation. The string returned is a stand-alone XML document marked as being in the UTF-8 charset.
      Parameters:
      id - the data identifier
      obj - the object to convert, or null
      Returns:
      an XML representation
    • unserialize

      public static Object unserialize(InputStream is) throws IOException
      Unserializes an object from an XML representation.
      Parameters:
      is - the input stream to load
      Returns:
      the object read
      Throws:
      IOException - if an error occurred while reading