Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > serialize generic objects to XML?

Reply
Thread Tools

serialize generic objects to XML?

 
 
Richard Chrenko
Guest
Posts: n/a
 
      10-07-2004
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?
 
Reply With Quote
 
 
 
 
Brusque
Guest
Posts: n/a
 
      10-07-2004

"Richard Chrenko" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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/


 
Reply With Quote
 
 
 
 
Richard Chrenko
Guest
Posts: n/a
 
      10-07-2004
On Thu, 7 Oct 2004 18:57:59 +1000, Brusque <(E-Mail Removed)>
wrote:

>
> "Richard Chrenko" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
>> 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/
>
>


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!!
 
Reply With Quote
 
Ann
Guest
Posts: n/a
 
      10-07-2004

"Richard Chrenko" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Richard Chrenko
Guest
Posts: n/a
 
      10-08-2004
On Thu, 07 Oct 2004 20:28:32 GMT, Ann <(E-Mail Removed)> wrote:

>
> "Richard Chrenko" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
>> 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.
>


When you say you "have used the encoder" which Java class are you
referring to, and does it encode to XML?
 
Reply With Quote
 
Ann
Guest
Posts: n/a
 
      10-08-2004

"Richard Chrenko" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> On Thu, 07 Oct 2004 20:28:32 GMT, Ann <(E-Mail Removed)> wrote:
>
> >
> > "Richard Chrenko" <(E-Mail Removed)> wrote in message
> > news(E-Mail Removed)...
> >> 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.
> >

>
> 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}));
}
}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to serialize domain objects? echoSwe@gmail.com ASP .Net 2 02-03-2007 11:12 PM
Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'. Mike Larkin ASP .Net 1 05-23-2005 12:33 PM
serialize to SQL Server Blob instead of XML serialize Gordz ASP .Net 3 06-07-2004 07:46 PM
Serialize java objects into XML ? H.Mittermaier Java 2 06-01-2004 09:31 PM
how to serialize java administrative objects from sun one as7 Siegfried Ertl Java 1 08-05-2003 06:08 AM



Advertisments