serialize generic objects to XML?

  • Thread starter Richard Chrenko
  • Start date
R

Richard Chrenko

I currently use ObjectOutputStream in order to serialize my objects.
However, in order to test and debug my code I really need a human-readable
output format. The XMLEncoder class does what I want, albeit only for
classes adhering to the JavaBean standard. Is there anything like an
"XMLOutputStream" which will convert the generic contents of an
ObjectOutputStream to XML?
 
B

Brusque

Richard Chrenko said:
I currently use ObjectOutputStream in order to serialize my objects.
However, in order to test and debug my code I really need a human-readable
output format. The XMLEncoder class does what I want, albeit only for
classes adhering to the JavaBean standard. Is there anything like an
"XMLOutputStream" which will convert the generic contents of an
ObjectOutputStream to XML?

http://xstream.codehaus.org/
 
R

Richard Chrenko


Thanks for the tip. Unfortunately my classes implement custom
serialization which, according to their website, codehaus does not support.

I have also tried the demo version of JSX which declares as a "feature"
that it serializes all attributes (even of parent classes not implementing
Serializable. The result is that for my relatively simple class which
happens to extend Observable, JSX is writing over 100 megabytes of
unwanted XML!!
 
A

Ann

Richard Chrenko said:
I currently use ObjectOutputStream in order to serialize my objects.
However, in order to test and debug my code I really need a human-readable
output format. The XMLEncoder class does what I want, albeit only for
classes adhering to the JavaBean standard. Is there anything like an
"XMLOutputStream" which will convert the generic contents of an
ObjectOutputStream to XML?

I don't have the code handy but I have used the encoder to encode
individual objects not the whole class. But I don't know if this is
supported officially.
 
R

Richard Chrenko

I don't have the code handy but I have used the encoder to encode
individual objects not the whole class. But I don't know if this is
supported officially.

When you say you "have used the encoder" which Java class are you
referring to, and does it encode to XML?
 
A

Ann

Richard Chrenko said:
When you say you "have used the encoder" which Java class are you
referring to, and does it encode to XML?

I searched for my code but deleted it. Maybe my 'pair programming'
partner has a copy. Anyway, I think it is the writeObject() method
(copy below) which is in
XMLEncoder.java (XMLEncoder.class)
in package java.beans;
which you can find in rt.jar
that comes with the J2SE distribution
============================================

/**
* Write an XML representation of the specified object to the output.
*
* @param o The object to be written to the stream.
*
* @see XMLDecoder#readObject
*/
public void writeObject(Object o) {
// System.out.println("XMLEncoder::writeObject: " +
instanceName(o));
if (internal) {
super.writeObject(o);
}
else {
writeStatement(new Statement(this, "writeObject", new
Object[]{o}));
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top