Using XMLEncoder to persist PlainDocument



I'm trying to use XMLEncoder for the first time. My need is to persist a PlainDocument to a file. Here is the code I'm using to do this:

ContentDocument content = ...; // where ContentDocument extends PlainDocument and gets initialized with some text

File file = new File( filename );
try
{
FileOutputStream fileOut = new FileOutputStream( file );
XMLEncoder e = new XMLEncoder( new BufferedOutputStream( fileOut ) );
e.writeObject( content );
e.close();
}
catch ( IOException ex )
{
JOptionPane.showMessageDialog( null, "Unable to save content:\n" + ex.getMessage() );
}


In my debugger, I've confirmed that the ContentDocument instance called "content" indeed contains some text.

When I open the file that is produced, here is what is in it:

<?xml version="1.0" encoding="UTF-8"?>
<java version="1.5.0_04" class="java.beans.XMLDecoder">
 <object class="com.neusys.hierarchicalpim.ContentDocument"/>
</java>

Clearly the text has not been included in what has been persisted. What am I doing wrong?

Thanks,
Dave Neuendorf
.