serialize generic objects to XML?

Discussion in 'Java' started by Richard Chrenko, Oct 7, 2004.

  1. 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?
     
    Richard Chrenko, Oct 7, 2004
    #1
    1. Advertising

  2. Richard Chrenko

    Brusque Guest

    "Richard Chrenko" <> wrote in message
    news:eek:...
    > 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/
     
    Brusque, Oct 7, 2004
    #2
    1. Advertising

  3. On Thu, 7 Oct 2004 18:57:59 +1000, Brusque <>
    wrote:

    >
    > "Richard Chrenko" <> wrote in message
    > news:eek:...
    >> 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!!
     
    Richard Chrenko, Oct 7, 2004
    #3
  4. Richard Chrenko

    Ann Guest

    "Richard Chrenko" <> wrote in message
    news:eek:...
    > 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.
     
    Ann, Oct 7, 2004
    #4
  5. On Thu, 07 Oct 2004 20:28:32 GMT, Ann <> wrote:

    >
    > "Richard Chrenko" <> wrote in message
    > news:eek:...
    >> 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?
     
    Richard Chrenko, Oct 8, 2004
    #5
  6. Richard Chrenko

    Ann Guest

    "Richard Chrenko" <> wrote in message
    news:eek:...
    > On Thu, 07 Oct 2004 20:28:32 GMT, Ann <> wrote:
    >
    > >
    > > "Richard Chrenko" <> wrote in message
    > > news:eek:...
    > >> 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}));
    }
    }
     
    Ann, Oct 8, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike Larkin
    Replies:
    1
    Views:
    6,115
    Alvin Bruney [MVP - ASP.NET]
    May 23, 2005
  2. Gordz
    Replies:
    3
    Views:
    3,974
    John Oakes
    Jun 7, 2004
  3. Siegfried Ertl
    Replies:
    1
    Views:
    304
    Roedy Green
    Aug 5, 2003
  4. H.Mittermaier

    Serialize java objects into XML ?

    H.Mittermaier, Jun 1, 2004, in forum: Java
    Replies:
    2
    Views:
    2,647
    iksrazal
    Jun 1, 2004
  5. Neil
    Replies:
    4
    Views:
    1,599
    Mike Schilling
    Sep 28, 2009
Loading...

Share This Page