Class XStreamer


  • public class XStreamer
    extends java.lang.Object
    Self-contained XStream generator. The class is a utility to write XML streams that contain additionally the XStream that was used to serialize the object graph. Such a stream can be unmarshalled using this embedded XStream instance, that kept any settings.
    Since:
    1.2
    • Constructor Summary

      Constructors 
      Constructor Description
      XStreamer()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object fromXML​(HierarchicalStreamDriver driver, java.io.Reader xml)
      Deserialize a self-contained XStream with object from an XML Reader.
      java.lang.Object fromXML​(HierarchicalStreamDriver driver, java.io.Reader xml, TypePermission[] permissions)
      Deserialize a self-contained XStream with object from an XML Reader.
      java.lang.Object fromXML​(HierarchicalStreamDriver driver, java.lang.String xml)
      Deserialize a self-contained XStream with object from a String.
      java.lang.Object fromXML​(HierarchicalStreamDriver driver, java.lang.String xml, TypePermission[] permissions)
      Deserialize a self-contained XStream with object from a String.
      java.lang.Object fromXML​(java.io.Reader xml)
      Deserialize a self-contained XStream with object from an XML Reader.
      java.lang.Object fromXML​(java.io.Reader xml, TypePermission[] permissions)
      Deserialize a self-contained XStream with object from an XML Reader.
      java.lang.Object fromXML​(java.lang.String xml)
      Deserialize a self-contained XStream with object from a String.
      java.lang.Object fromXML​(java.lang.String xml, TypePermission[] permissions)
      Deserialize a self-contained XStream with object from a String.
      static TypePermission[] getDefaultPermissions()
      Retrieve the default permissions to unmarshal an XStream instance.
      java.lang.String toXML​(XStream xstream, java.lang.Object obj)
      Serialize an object including the XStream to a pretty-printed XML String.
      void toXML​(XStream xstream, java.lang.Object obj, java.io.Writer out)
      Serialize an object including the XStream to the given Writer as pretty-printed XML.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • XStreamer

        public XStreamer()
    • Method Detail

      • toXML

        public java.lang.String toXML​(XStream xstream,
                                      java.lang.Object obj)
                               throws java.io.ObjectStreamException
        Serialize an object including the XStream to a pretty-printed XML String.
        Throws:
        java.io.ObjectStreamException - if the XML contains non-serializable elements
        XStreamException - if the object cannot be serialized
        Since:
        1.2
        See Also:
        toXML(XStream, Object, Writer)
      • toXML

        public void toXML​(XStream xstream,
                          java.lang.Object obj,
                          java.io.Writer out)
                   throws java.io.IOException
        Serialize an object including the XStream to the given Writer as pretty-printed XML.

        Warning: XStream will serialize itself into this XML stream. To read such an XML code, you should use fromXML(Reader) or one of the other overloaded methods. Since a lot of internals are written into the stream, you cannot expect to use such an XML to work with another XStream version or with XStream running on different JDKs and/or versions. We have currently no JDK 1.3 support, nor will the PureReflectionConverter work with a JDK less than 1.5.

        Throws:
        java.io.IOException - if an error occurs reading from the Writer.
        XStreamException - if the object cannot be serialized
        Since:
        1.2
      • fromXML

        public java.lang.Object fromXML​(java.lang.String xml)
                                 throws java.lang.ClassNotFoundException,
                                        java.io.ObjectStreamException
        Deserialize a self-contained XStream with object from a String. The method will use internally an XppDriver to load the contained XStream instance with default permissions.
        Parameters:
        xml - the XML data
        Throws:
        java.lang.ClassNotFoundException - if a class in the XML stream cannot be found
        java.io.ObjectStreamException - if the XML contains non-deserializable elements
        XStreamException - if the object cannot be deserialized
        Since:
        1.2
        See Also:
        toXML(XStream, Object, Writer)
      • fromXML

        public java.lang.Object fromXML​(java.lang.String xml,
                                        TypePermission[] permissions)
                                 throws java.lang.ClassNotFoundException,
                                        java.io.ObjectStreamException
        Deserialize a self-contained XStream with object from a String. The method will use internally an XppDriver to load the contained XStream instance.
        Parameters:
        xml - the XML data
        permissions - the permissions to use (ensure that they include the defaults)
        Throws:
        java.lang.ClassNotFoundException - if a class in the XML stream cannot be found
        java.io.ObjectStreamException - if the XML contains non-deserializable elements
        XStreamException - if the object cannot be deserialized
        Since:
        1.4.7
        See Also:
        toXML(XStream, Object, Writer)
      • fromXML

        public java.lang.Object fromXML​(HierarchicalStreamDriver driver,
                                        java.lang.String xml)
                                 throws java.lang.ClassNotFoundException,
                                        java.io.ObjectStreamException
        Deserialize a self-contained XStream with object from a String.
        Parameters:
        driver - the implementation to use
        xml - the XML data
        Throws:
        java.lang.ClassNotFoundException - if a class in the XML stream cannot be found
        java.io.ObjectStreamException - if the XML contains non-deserializable elements
        XStreamException - if the object cannot be deserialized
        Since:
        1.2
        See Also:
        toXML(XStream, Object, Writer)
      • fromXML

        public java.lang.Object fromXML​(HierarchicalStreamDriver driver,
                                        java.lang.String xml,
                                        TypePermission[] permissions)
                                 throws java.lang.ClassNotFoundException,
                                        java.io.ObjectStreamException
        Deserialize a self-contained XStream with object from a String.
        Parameters:
        driver - the implementation to use
        xml - the XML data
        permissions - the permissions to use (ensure that they include the defaults)
        Throws:
        java.lang.ClassNotFoundException - if a class in the XML stream cannot be found
        java.io.ObjectStreamException - if the XML contains non-deserializable elements
        XStreamException - if the object cannot be deserialized
        Since:
        1.4.7
        See Also:
        toXML(XStream, Object, Writer)
      • fromXML

        public java.lang.Object fromXML​(java.io.Reader xml)
                                 throws java.io.IOException,
                                        java.lang.ClassNotFoundException
        Deserialize a self-contained XStream with object from an XML Reader. The method will use internally an XppDriver to load the contained XStream instance with default permissions.
        Parameters:
        xml - the Reader providing the XML data
        Throws:
        java.io.IOException - if an error occurs reading from the Reader.
        java.lang.ClassNotFoundException - if a class in the XML stream cannot be found
        XStreamException - if the object cannot be deserialized
        Since:
        1.2
        See Also:
        toXML(XStream, Object, Writer)
      • fromXML

        public java.lang.Object fromXML​(java.io.Reader xml,
                                        TypePermission[] permissions)
                                 throws java.io.IOException,
                                        java.lang.ClassNotFoundException
        Deserialize a self-contained XStream with object from an XML Reader. The method will use internally an XppDriver to load the contained XStream instance.
        Parameters:
        xml - the Reader providing the XML data
        permissions - the permissions to use (ensure that they include the defaults)
        Throws:
        java.io.IOException - if an error occurs reading from the Reader.
        java.lang.ClassNotFoundException - if a class in the XML stream cannot be found
        XStreamException - if the object cannot be deserialized
        Since:
        1.4.7
        See Also:
        toXML(XStream, Object, Writer)
      • fromXML

        public java.lang.Object fromXML​(HierarchicalStreamDriver driver,
                                        java.io.Reader xml)
                                 throws java.io.IOException,
                                        java.lang.ClassNotFoundException
        Deserialize a self-contained XStream with object from an XML Reader.
        Parameters:
        driver - the implementation to use
        xml - the Reader providing the XML data
        Throws:
        java.io.IOException - if an error occurs reading from the Reader.
        java.lang.ClassNotFoundException - if a class in the XML stream cannot be found
        XStreamException - if the object cannot be deserialized
        Since:
        1.2
      • fromXML

        public java.lang.Object fromXML​(HierarchicalStreamDriver driver,
                                        java.io.Reader xml,
                                        TypePermission[] permissions)
                                 throws java.io.IOException,
                                        java.lang.ClassNotFoundException
        Deserialize a self-contained XStream with object from an XML Reader.
        Parameters:
        driver - the implementation to use
        xml - the Reader providing the XML data
        permissions - the permissions to use (ensure that they include the defaults)
        Throws:
        java.io.IOException - if an error occurs reading from the Reader.
        java.lang.ClassNotFoundException - if a class in the XML stream cannot be found
        XStreamException - if the object cannot be deserialized
        Since:
        1.4.7
      • getDefaultPermissions

        public static TypePermission[] getDefaultPermissions()
        Retrieve the default permissions to unmarshal an XStream instance.

        The returned list will only cover permissions for XStream's own types. If your custom converters or mappers keep references to other types, you will have to add permission for those types on your own.

        Since:
        1.4.7