Re: Decoding XML

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Mar 10 2005 - 23:30:24 EST

  • Next message: Tore Halset: "Re: Joint Prefetches"

    On Mar 9, 2005, at 8:43 AM, Kevin Menard wrote:

    >
    > Reader xml = new FileReader(XML_DATA_DIR + "encoded-object.xml");
    > XMLDecoder decoder = new XMLDecoder;
    > TestObject object = (TestObject) decoder.decode(xml);
    >
    > Compare the above with the following:
    >
    > Reader xml = new FileReader(XML_DATA_DIR + "encoded-object.xml");
    > XMLDecoder decoder = new XMLDecoder(xml);
    > TestObject object = new TestObject(decoder);

    I too prefer the first method - it seems cleaner, and no-arg
    constructor requirement is no big deal. Besides second choice seems to
    limit the ability to provide subclasses (or alternative interface
    implementations) within the decoded tree, as all object constructors
    have to be called explicitly.

    Still my intuition maybe wrong, as I have only limited experience with
    XML coding scenarios (even worse - this one is in an environment that
    tends to provide the most complex solutions to the most simple problems
    .. oh well).

    On a side note, I tried a few popular XML coding frameworks (JAXB and
    XMLBeans), and while they work, they seem to be pretty inflexible (JAXB
    is actually pretty easy, but the amount of code it generates is just
    insane!!). Looks like another case of Java mainstream doing it all
    wrong. Watch out for someone coming with an "innovative" XML solution 5
    years from now :-)

    Andrus



    This archive was generated by hypermail 2.0.0 : Thu Mar 10 2005 - 23:30:27 EST