Package org.simpleframework.xml
Interface Serializer
- All Known Implementing Classes:
Persister
public interface Serializer
The
Serializer
interface is used to represent objects
that can serialize and deserialize objects to an from XML. This
exposes several read
and write
methods
that can read from and write to various sources. Typically an
object will be read from an XML file and written to some other
file or stream.
An implementation of the Serializer
interface is free
to use any desired XML parsing framework. If a framework other
than the Java streaming API for XML is required then it should be
wrapped within the org.simpleframework.xml.stream
API,
which offers a framework neutral facade.
-
Method Summary
Modifier and TypeMethodDescription<T> T
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type.<T> T
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type.<T> T
read
(Class<? extends T> type, InputStream source) Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type.<T> T
read
(Class<? extends T> type, InputStream source, boolean strict) Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type.<T> T
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type.<T> T
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type.<T> T
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type.<T> T
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type.<T> T
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type.<T> T
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type.<T> T
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized.<T> T
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized.<T> T
read
(T value, InputStream source) Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized.<T> T
read
(T value, InputStream source, boolean strict) Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized.<T> T
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized.<T> T
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized.<T> T
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized.<T> T
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized.<T> T
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized.<T> T
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized.boolean
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema.boolean
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema.boolean
validate
(Class type, InputStream source) Thisvalidate
method will validate the contents of the XML document against the specified XML class schema.boolean
validate
(Class type, InputStream source, boolean strict) Thisvalidate
method will validate the contents of the XML document against the specified XML class schema.boolean
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema.boolean
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema.boolean
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema.boolean
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema.boolean
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema.boolean
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema.void
Thiswrite
method will traverse the provided object checking for field annotations in order to compose the XML data.void
write
(Object source, OutputStream out) Thiswrite
method will traverse the provided object checking for field annotations in order to compose the XML data.void
Thiswrite
method will traverse the provided object checking for field annotations in order to compose the XML data.void
write
(Object source, OutputNode root) Thiswrite
method will traverse the provided object checking for field annotations in order to compose the XML data.
-
Method Details
-
read
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown. The instance deserialized is returned.- Parameters:
type
- this is the class type to be deserialized from XMLsource
- this provides the source of the XML document- Returns:
- the object deserialized from the XML document
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown. The instance deserialized is returned.- Parameters:
type
- this is the class type to be deserialized from XMLsource
- this provides the source of the XML document- Returns:
- the object deserialized from the XML document
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown. The instance deserialized is returned.- Parameters:
type
- this is the class type to be deserialized from XMLsource
- this provides the source of the XML document- Returns:
- the object deserialized from the XML document
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown. The instance deserialized is returned.- Parameters:
type
- this is the class type to be deserialized from XMLsource
- this provides the source of the XML document- Returns:
- the object deserialized from the XML document
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown. The instance deserialized is returned.- Parameters:
type
- this is the class type to be deserialized from XMLsource
- this provides the source of the XML document- Returns:
- the object deserialized from the XML document
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown. The instance deserialized is returned.- Parameters:
type
- this is the class type to be deserialized from XMLsource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- the object deserialized from the XML document
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown. The instance deserialized is returned.- Parameters:
type
- this is the class type to be deserialized from XMLsource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- the object deserialized from the XML document
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown. The instance deserialized is returned.- Parameters:
type
- this is the class type to be deserialized from XMLsource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- the object deserialized from the XML document
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown. The instance deserialized is returned.- Parameters:
type
- this is the class type to be deserialized from XMLsource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- the object deserialized from the XML document
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and convert it into an object of the specified type. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown. The instance deserialized is returned.- Parameters:
type
- this is the class type to be deserialized from XMLsource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- the object deserialized from the XML document
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized. This is used as a means of injecting an object with values deserialized from an XML document. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown.- Parameters:
value
- this is the object to deserialize the XML in tosource
- this provides the source of the XML document- Returns:
- the same instance provided is returned when finished
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized. This is used as a means of injecting an object with values deserialized from an XML document. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown.- Parameters:
value
- this is the object to deserialize the XML in tosource
- this provides the source of the XML document- Returns:
- the same instance provided is returned when finished
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized. This is used as a means of injecting an object with values deserialized from an XML document. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown.- Parameters:
value
- this is the object to deserialize the XML in tosource
- this provides the source of the XML document- Returns:
- the same instance provided is returned when finished
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized. This is used as a means of injecting an object with values deserialized from an XML document. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown.- Parameters:
value
- this is the object to deserialize the XML in tosource
- this provides the source of the XML document- Returns:
- the same instance provided is returned when finished
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized. This is used as a means of injecting an object with values deserialized from an XML document. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown.- Parameters:
value
- this is the object to deserialize the XML in tosource
- this provides the source of the XML document- Returns:
- the same instance provided is returned when finished
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized. This is used as a means of injecting an object with values deserialized from an XML document. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown.- Parameters:
value
- this is the object to deserialize the XML in tosource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- the same instance provided is returned when finished
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized. This is used as a means of injecting an object with values deserialized from an XML document. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown.- Parameters:
value
- this is the object to deserialize the XML in tosource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- the same instance provided is returned when finished
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized. This is used as a means of injecting an object with values deserialized from an XML document. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown.- Parameters:
value
- this is the object to deserialize the XML in tosource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- the same instance provided is returned when finished
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized. This is used as a means of injecting an object with values deserialized from an XML document. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown.- Parameters:
value
- this is the object to deserialize the XML in tosource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- the same instance provided is returned when finished
- Throws:
Exception
- if the object cannot be fully deserialized
-
read
Thisread
method will read the contents of the XML document from the provided source and populate the object with the values deserialized. This is used as a means of injecting an object with values deserialized from an XML document. If the XML source cannot be deserialized or there is a problem building the object graph an exception is thrown.- Parameters:
value
- this is the object to deserialize the XML in tosource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- the same instance provided is returned when finished
- Throws:
Exception
- if the object cannot be fully deserialized
-
validate
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema. This is used to perform a read traversal of the class schema such that the document can be tested against it. This is preferred to reading the document as it does not instantiate the objects or invoke any callback methods, thus making it a safe validation.- Parameters:
type
- this is the class type to be validated against XMLsource
- this provides the source of the XML document- Returns:
- true if the document matches the class XML schema
- Throws:
Exception
- if the class XML schema does not fully match
-
validate
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema. This is used to perform a read traversal of the class schema such that the document can be tested against it. This is preferred to reading the document as it does not instantiate the objects or invoke any callback methods, thus making it a safe validation.- Parameters:
type
- this is the class type to be validated against XMLsource
- this provides the source of the XML document- Returns:
- true if the document matches the class XML schema
- Throws:
Exception
- if the class XML schema does not fully match
-
validate
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema. This is used to perform a read traversal of the class schema such that the document can be tested against it. This is preferred to reading the document as it does not instantiate the objects or invoke any callback methods, thus making it a safe validation.- Parameters:
type
- this is the class type to be validated against XMLsource
- this provides the source of the XML document- Returns:
- true if the document matches the class XML schema
- Throws:
Exception
- if the class XML schema does not fully match
-
validate
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema. This is used to perform a read traversal of the class schema such that the document can be tested against it. This is preferred to reading the document as it does not instantiate the objects or invoke any callback methods, thus making it a safe validation.- Parameters:
type
- this is the class type to be validated against XMLsource
- this provides the source of the XML document- Returns:
- true if the document matches the class XML schema
- Throws:
Exception
- if the class XML schema does not fully match
-
validate
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema. This is used to perform a read traversal of the class schema such that the document can be tested against it. This is preferred to reading the document as it does not instantiate the objects or invoke any callback methods, thus making it a safe validation.- Parameters:
type
- this is the class type to be validated against XMLsource
- this provides the source of the XML document- Returns:
- true if the document matches the class XML schema
- Throws:
Exception
- if the class XML schema does not fully match
-
validate
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema. This is used to perform a read traversal of the class schema such that the document can be tested against it. This is preferred to reading the document as it does not instantiate the objects or invoke any callback methods, thus making it a safe validation.- Parameters:
type
- this is the class type to be validated against XMLsource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- true if the document matches the class XML schema
- Throws:
Exception
- if the class XML schema does not fully match
-
validate
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema. This is used to perform a read traversal of the class schema such that the document can be tested against it. This is preferred to reading the document as it does not instantiate the objects or invoke any callback methods, thus making it a safe validation.- Parameters:
type
- this is the class type to be validated against XMLsource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- true if the document matches the class XML schema
- Throws:
Exception
- if the class XML schema does not fully match
-
validate
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema. This is used to perform a read traversal of the class schema such that the document can be tested against it. This is preferred to reading the document as it does not instantiate the objects or invoke any callback methods, thus making it a safe validation.- Parameters:
type
- this is the class type to be validated against XMLsource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- true if the document matches the class XML schema
- Throws:
Exception
- if the class XML schema does not fully match
-
validate
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema. This is used to perform a read traversal of the class schema such that the document can be tested against it. This is preferred to reading the document as it does not instantiate the objects or invoke any callback methods, thus making it a safe validation.- Parameters:
type
- this is the class type to be validated against XMLsource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- true if the document matches the class XML schema
- Throws:
Exception
- if the class XML schema does not fully match
-
validate
Thisvalidate
method will validate the contents of the XML document against the specified XML class schema. This is used to perform a read traversal of the class schema such that the document can be tested against it. This is preferred to reading the document as it does not instantiate the objects or invoke any callback methods, thus making it a safe validation.- Parameters:
type
- this is the class type to be validated against XMLsource
- this provides the source of the XML documentstrict
- this determines whether to read in strict mode- Returns:
- true if the document matches the class XML schema
- Throws:
Exception
- if the class XML schema does not fully match
-
write
Thiswrite
method will traverse the provided object checking for field annotations in order to compose the XML data. This uses thegetClass
method on the object to determine the class file that will be used to compose the schema. If there is noRoot
annotation for the class then this will throw an exception. The root annotation is the only annotation required for an object to be serialized.- Parameters:
source
- this is the object that is to be serializedout
- this is where the serialized XML is written to- Throws:
Exception
- if the schema for the object is not valid
-
write
Thiswrite
method will traverse the provided object checking for field annotations in order to compose the XML data. This uses thegetClass
method on the object to determine the class file that will be used to compose the schema. If there is noRoot
annotation for the class then this will throw an exception. The root annotation is the only annotation required for an object to be serialized.- Parameters:
source
- this is the object that is to be serializedout
- this is where the serialized XML is written to- Throws:
Exception
- if the schema for the object is not valid
-
write
Thiswrite
method will traverse the provided object checking for field annotations in order to compose the XML data. This uses thegetClass
method on the object to determine the class file that will be used to compose the schema. If there is noRoot
annotation for the class then this will throw an exception. The root annotation is the only annotation required for an object to be serialized.- Parameters:
source
- this is the object that is to be serializedout
- this is where the serialized XML is written to- Throws:
Exception
- if the schema for the object is not valid
-
write
Thiswrite
method will traverse the provided object checking for field annotations in order to compose the XML data. This uses thegetClass
method on the object to determine the class file that will be used to compose the schema. If there is noRoot
annotation for the class then this will throw an exception. The root annotation is the only annotation required for an object to be serialized.- Parameters:
source
- this is the object that is to be serializedroot
- this is where the serialized XML is written to- Throws:
Exception
- if the schema for the object is not valid
-