Aracılığıyla paylaş


XmlSerializable<T> Interface

Type Parameters

T

The type of the object that is XML serializable.

public interface XmlSerializable

Indicates that the implementing class can be serialized to and deserialized from XML.

Since deserialization needs to work without an instance of the class, implementing this interface it's assumed the class has a static method fromXml(XmlReader) that deserializes an instance of that class. The contract for reading XML... TODO (alzimmer): finish this javadoc

Method Summary

Modifier and Type Method and Description
static T fromXml(XmlReader xmlReader)

Reads an XML stream into an object.

static T fromXml(XmlReader xmlReader, String rootElementName)

Reads an XML stream into an object.

abstract XmlWriter toXml(XmlWriter xmlWriter)

Writes the object to the passed XmlWriter.

abstract XmlWriter toXml(XmlWriter xmlWriter, String rootElementName)

Writes the object to the passed XmlWriter.

Method Details

fromXml

public static T fromXml(XmlReader xmlReader)

Reads an XML stream into an object.

Implementations of XmlSerializable<T> must define this method, otherwise an UnsupportedOperationException will be thrown.

Parameters:

xmlReader - The XmlReader being read.

Returns:

The object that the XML stream represented, may return null.

Throws:

XMLStreamException

- If an object fails to be read from the xmlReader.

fromXml

public static T fromXml(XmlReader xmlReader, String rootElementName)

Reads an XML stream into an object.

Implementations of XmlSerializable<T> must define this method, otherwise an UnsupportedOperationException will be thrown.

Parameters:

xmlReader - The XmlReader being read.
rootElementName - Optional root element name to override the default defined by the model. Used to support cases where the model can deserialize from different root element names.

Returns:

The object that the XML stream represented, may return null.

Throws:

XMLStreamException

- If an object fails to be read from the xmlReader.

toXml

public abstract XmlWriter toXml(XmlWriter xmlWriter)

Writes the object to the passed XmlWriter.

The contract for writing XML to XmlWriter is that the object being written will handle opening and closing its own XML object. So, for objects calling out to other XmlSerializable<T> objects for serialization, they'll pass the XmlWriter to the other XmlSerializable<T> object. This way objects writing XML will be self-encapsulated for writing properly formatted XML.

Parameters:

xmlWriter - The XmlWriter being written to.

Returns:

The XmlWriter where the JSON was written for chaining.

Throws:

XMLStreamException

- If the object fails to be written to the xmlWriter.

toXml

public abstract XmlWriter toXml(XmlWriter xmlWriter, String rootElementName)

Writes the object to the passed XmlWriter.

The contract for writing XML to XmlWriter is that the object being written will handle opening and closing its own XML object. So, for objects calling out to other XmlSerializable<T> objects for serialization, they'll pass the XmlWriter to the other XmlSerializable<T> object. This way objects writing XML will be self-encapsulated for writing properly formatted XML.

Parameters:

xmlWriter - The XmlWriter being written to.
rootElementName - Optional root element name to override the default defined by the model. Used to support cases where the model can serialize using different root element names.

Returns:

The XmlWriter where the JSON was written for chaining.

Throws:

XMLStreamException

- If the object fails to be written to the xmlWriter.

Applies to