Package com.thoughtworks.xstream
Class XStreamer
java.lang.Object
com.thoughtworks.xstream.XStreamer
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
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfromXML
(HierarchicalStreamDriver driver, Reader xml) Deserialize a self-contained XStream with object from an XML Reader.fromXML
(HierarchicalStreamDriver driver, Reader xml, TypePermission[] permissions) Deserialize a self-contained XStream with object from an XML Reader.fromXML
(HierarchicalStreamDriver driver, String xml) Deserialize a self-contained XStream with object from a String.fromXML
(HierarchicalStreamDriver driver, String xml, TypePermission[] permissions) Deserialize a self-contained XStream with object from a String.Deserialize a self-contained XStream with object from an XML Reader.fromXML
(Reader xml, TypePermission[] permissions) Deserialize a self-contained XStream with object from an XML Reader.Deserialize a self-contained XStream with object from a String.fromXML
(String xml, TypePermission[] permissions) Deserialize a self-contained XStream with object from a String.static TypePermission[]
Retrieve the default permissions to unmarshal an XStream instance.Serialize an object including the XStream to a pretty-printed XML String.void
Serialize an object including the XStream to the given Writer as pretty-printed XML.
-
Field Details
-
PERMISSIONS
-
-
Constructor Details
-
XStreamer
public XStreamer()
-
-
Method Details
-
toXML
Serialize an object including the XStream to a pretty-printed XML String.- Throws:
ObjectStreamException
- if the XML contains non-serializable elementsXStreamException
- if the object cannot be serialized- Since:
- 1.2
- See Also:
-
toXML
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:
IOException
- if an error occurs reading from the Writer.XStreamException
- if the object cannot be serialized- Since:
- 1.2
-
fromXML
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:
ClassNotFoundException
- if a class in the XML stream cannot be foundObjectStreamException
- if the XML contains non-deserializable elementsXStreamException
- if the object cannot be deserialized- Since:
- 1.2
- See Also:
-
fromXML
public Object fromXML(String xml, 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
- the XML datapermissions
- the permissions to use (ensure that they include the defaults)- Throws:
ClassNotFoundException
- if a class in the XML stream cannot be foundObjectStreamException
- if the XML contains non-deserializable elementsXStreamException
- if the object cannot be deserialized- Since:
- 1.4.7
- See Also:
-
fromXML
public Object fromXML(HierarchicalStreamDriver driver, String xml) throws ClassNotFoundException, ObjectStreamException Deserialize a self-contained XStream with object from a String.- Parameters:
driver
- the implementation to usexml
- the XML data- Throws:
ClassNotFoundException
- if a class in the XML stream cannot be foundObjectStreamException
- if the XML contains non-deserializable elementsXStreamException
- if the object cannot be deserialized- Since:
- 1.2
- See Also:
-
fromXML
public Object fromXML(HierarchicalStreamDriver driver, String xml, TypePermission[] permissions) throws ClassNotFoundException, ObjectStreamException Deserialize a self-contained XStream with object from a String.- Parameters:
driver
- the implementation to usexml
- the XML datapermissions
- the permissions to use (ensure that they include the defaults)- Throws:
ClassNotFoundException
- if a class in the XML stream cannot be foundObjectStreamException
- if the XML contains non-deserializable elementsXStreamException
- if the object cannot be deserialized- Since:
- 1.4.7
- See Also:
-
fromXML
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
- theReader
providing the XML data- Throws:
IOException
- if an error occurs reading from the Reader.ClassNotFoundException
- if a class in the XML stream cannot be foundXStreamException
- if the object cannot be deserialized- Since:
- 1.2
- See Also:
-
fromXML
public Object fromXML(Reader xml, 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
- theReader
providing the XML datapermissions
- the permissions to use (ensure that they include the defaults)- Throws:
IOException
- if an error occurs reading from the Reader.ClassNotFoundException
- if a class in the XML stream cannot be foundXStreamException
- if the object cannot be deserialized- Since:
- 1.4.7
- See Also:
-
fromXML
public Object fromXML(HierarchicalStreamDriver driver, Reader xml) throws IOException, ClassNotFoundException Deserialize a self-contained XStream with object from an XML Reader.- Parameters:
driver
- the implementation to usexml
- theReader
providing the XML data- Throws:
IOException
- if an error occurs reading from the Reader.ClassNotFoundException
- if a class in the XML stream cannot be foundXStreamException
- if the object cannot be deserialized- Since:
- 1.2
-
fromXML
public Object fromXML(HierarchicalStreamDriver driver, Reader xml, TypePermission[] permissions) throws IOException, ClassNotFoundException Deserialize a self-contained XStream with object from an XML Reader.- Parameters:
driver
- the implementation to usexml
- theReader
providing the XML datapermissions
- the permissions to use (ensure that they include the defaults)- Throws:
IOException
- if an error occurs reading from the Reader.ClassNotFoundException
- if a class in the XML stream cannot be foundXStreamException
- if the object cannot be deserialized- Since:
- 1.4.7
-
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
-