public final class XMLSerializer extends Object
There is no mechanism to prevent infinite loops if some objects (lists,...) reference themselves.
The underlying XML document is generated using an XML string buffer.
| Constructor and Description |
|---|
XMLSerializer(XMLWriter xml)
Creates a new XML serializer using the specified XML writer.
|
| Modifier and Type | Method and Description |
|---|---|
XMLWriter |
getXML()
Returns the underlying XML document.
|
void |
serialize(Object o,
String name)
Serialises the given object using the given name as element name.
|
void |
serializeCollection(Collection<?> c)
Serialises the given Collection to xml.
|
void |
serializeHashtable(Hashtable<?,?> h)
Serialise the given
Hashtable to xml. |
void |
serializeObject(Object o)
Serialises the given object to xml by using the public methods
getXXX(). |
public XMLSerializer(XMLWriter xml)
xml - The XML string buffer to be usedpublic XMLWriter getXML()
public void serialize(Object o, String name) throws IOException
This implementation is recursive. It calls itself for fields which are not of primitive type.
o - Object to be serialised as xmlname - Name of objectIOException - Should an I/O error occur.public void serializeCollection(Collection<?> c) throws IOException
Iterates over every object and call the serialize(java.lang.Object, java.lang.String) method.
c - The Collection to be serialised to XMLIOException - Should an I/O error occur.public void serializeHashtable(Hashtable<?,?> h) throws IOException
Hashtable to xml.
This methods only works if the Hashtable contains String
objects.
h - The hashtable to be serialized to XMLIOException - Should an I/O error occur.public void serializeObject(Object o) throws IOException
getXXX().
This method calls every getXXX() method from the object to get the
returned object and then calls the serialize(Object, String) method with
the returned object and the name xxx in lower case.
o - The object to be serialised as XMLIOException - Should an I/O error occur.Copyright © 2007-2022. All Rights Reserved.