Top Description Fields Constructors Methods
com.thoughtworks.xstream

public Class XStreamer

extends Object
Class Inheritance
Imports
java.io.IOException, .ObjectInputStream, .ObjectOutputStream, .ObjectStreamException, .Reader, .StringReader, .StringWriter, .Writer, javax.xml.datatype.DatatypeFactory, com.thoughtworks.xstream.converters.ConverterLookup, .ConverterMatcher, .ConverterRegistry, .MarshallingContext, .UnmarshallingContext, com.thoughtworks.xstream.converters.javabean.JavaBeanProvider, com.thoughtworks.xstream.converters.reflection.FieldKeySorter, .ReflectionProvider, com.thoughtworks.xstream.core.JVM, com.thoughtworks.xstream.io.HierarchicalStreamDriver, .HierarchicalStreamReader, .StreamException, com.thoughtworks.xstream.io.naming.NameCoder, com.thoughtworks.xstream.io.xml.XppDriver, com.thoughtworks.xstream.mapper.Mapper, com.thoughtworks.xstream.security.TypeHierarchyPermission, .TypePermission, .WildcardTypePermission

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.
Author
Jörg Schaible
Since
1.2

Field Summary

Modifier and TypeField and Description
private static final TypePermission[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
fromXML(final String
the XML data
xml
)

Deserialize a self-contained XStream with object from a String.

public Object
fromXML(final String
the XML data
xml
,
final TypePermission[]
the permissions to use (ensure that they include the defaults)
permissions
)

Deserialize a self-contained XStream with object from a String.

public Object
fromXML(final HierarchicalStreamDriver
the implementation to use
driver
,
final String
the XML data
xml
)

Deserialize a self-contained XStream with object from a String.

public Object
fromXML(final HierarchicalStreamDriver
the implementation to use
driver
,
final String
the XML data
xml
,
final TypePermission[]
the permissions to use (ensure that they include the defaults)
permissions
)

Deserialize a self-contained XStream with object from a String.

public Object
fromXML(final Reader
the Reader providing the XML data
xml
)

Deserialize a self-contained XStream with object from an XML Reader.

public Object
fromXML(final Reader
the Reader providing the XML data
xml
,
final TypePermission[]
the permissions to use (ensure that they include the defaults)
permissions
)

Deserialize a self-contained XStream with object from an XML Reader.

public Object
fromXML(final HierarchicalStreamDriver
the implementation to use
driver
,
final Reader
the Reader providing the XML data
xml
)

Deserialize a self-contained XStream with object from an XML Reader.

public Object
fromXML(final HierarchicalStreamDriver
the implementation to use
driver
,
final Reader
the Reader providing the XML data
xml
,
final TypePermission[]
the permissions to use (ensure that they include the defaults)
permissions
)

Deserialize a self-contained XStream with object from an XML Reader.

public static TypePermission[]
getDefaultPermissions()

Retrieve the default permissions to unmarshal an XStream instance.

public String
toXML(final XStream xstream, final Object obj)

Serialize an object including the XStream to a pretty-printed XML String.

public void
toXML(final XStream xstream, final Object obj, final Writer out)

Serialize an object including the XStream to the given Writer as pretty-printed XML.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

PERMISSIONSback to summary
private static final TypePermission[] PERMISSIONS

Constructor Detail

XStreamerback to summary
public XStreamer()

Method Detail

fromXMLback to summary
public Object fromXML(final String xml) throws ClassNotFoundException, 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:String

the XML data

Exceptions
ClassNotFoundException:
if a class in the XML stream cannot be found
ObjectStreamException:
if the XML contains non-deserializable elements
XStreamException:
if the object cannot be deserialized
Since
1.2
See Also
toXML(XStream, Object, Writer)
fromXMLback to summary
public Object fromXML(final String xml, final TypePermission[] permissions) throws ClassNotFoundException, 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:String

the XML data

permissions:TypePermission[]

the permissions to use (ensure that they include the defaults)

Exceptions
ClassNotFoundException:
if a class in the XML stream cannot be found
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)
fromXMLback to summary
public Object fromXML(final HierarchicalStreamDriver driver, final String xml) throws ClassNotFoundException, ObjectStreamException

Deserialize a self-contained XStream with object from a String.

Parameters
driver:HierarchicalStreamDriver

the implementation to use

xml:String

the XML data

Exceptions
ClassNotFoundException:
if a class in the XML stream cannot be found
ObjectStreamException:
if the XML contains non-deserializable elements
XStreamException:
if the object cannot be deserialized
Since
1.2
See Also
toXML(XStream, Object, Writer)
fromXMLback to summary
public Object fromXML(final HierarchicalStreamDriver driver, final String xml, final TypePermission[] permissions) throws ClassNotFoundException, ObjectStreamException

Deserialize a self-contained XStream with object from a String.

Parameters
driver:HierarchicalStreamDriver

the implementation to use

xml:String

the XML data

permissions:TypePermission[]

the permissions to use (ensure that they include the defaults)

Exceptions
ClassNotFoundException:
if a class in the XML stream cannot be found
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)
fromXMLback to summary
public Object fromXML(final Reader xml) throws IOException, 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:Reader

the Reader providing the XML data

Exceptions
IOException:
if an error occurs reading from the Reader.
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)
fromXMLback to summary
public Object fromXML(final Reader xml, final TypePermission[] permissions) throws IOException, 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:Reader

the Reader providing the XML data

permissions:TypePermission[]

the permissions to use (ensure that they include the defaults)

Exceptions
IOException:
if an error occurs reading from the Reader.
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)
fromXMLback to summary
public Object fromXML(final HierarchicalStreamDriver driver, final Reader xml) throws IOException, ClassNotFoundException

Deserialize a self-contained XStream with object from an XML Reader.

Parameters
driver:HierarchicalStreamDriver

the implementation to use

xml:Reader

the Reader providing the XML data

Exceptions
IOException:
if an error occurs reading from the Reader.
ClassNotFoundException:
if a class in the XML stream cannot be found
XStreamException:
if the object cannot be deserialized
Since
1.2
fromXMLback to summary
public Object fromXML(final HierarchicalStreamDriver driver, final Reader xml, final TypePermission[] permissions) throws IOException, ClassNotFoundException

Deserialize a self-contained XStream with object from an XML Reader.

Parameters
driver:HierarchicalStreamDriver

the implementation to use

xml:Reader

the Reader providing the XML data

permissions:TypePermission[]

the permissions to use (ensure that they include the defaults)

Exceptions
IOException:
if an error occurs reading from the Reader.
ClassNotFoundException:
if a class in the XML stream cannot be found
XStreamException:
if the object cannot be deserialized
Since
1.4.7
getDefaultPermissionsback to summary
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
toXMLback to summary
public String toXML(final XStream xstream, final Object obj) throws ObjectStreamException

Serialize an object including the XStream to a pretty-printed XML String.

Exceptions
ObjectStreamException:
if the XML contains non-serializable elements
XStreamException:
if the object cannot be serialized
Since
1.2
See Also
toXML(XStream, Object, Writer)
toXMLback to summary
public void toXML(final XStream xstream, final Object obj, final Writer out) throws 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 XStreamer#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.

Exceptions
IOException:
if an error occurs reading from the Writer.
XStreamException:
if the object cannot be serialized
Since
1.2