Re: XML Serialization

From: John Martyniak (jmarty..x.netcom.com)
Date: Thu May 12 2005 - 13:53:56 EDT

  • Next message: Andrus Adamchik: "Re: XML Serialization"

    Andrus,

    I just ran a couple of tests using the Xstream stuff, using some test
    examples I have been using with our XMLcoder and Decoder.

    Here is the code that I added to the cayenne-web-app example:

            XStream xstream = new XStream(new DomDriver()); // does not require
    XPP3 library

            xstream.alias("artist", Artist.class);
                      
            String xml = xstream.toXML(artists);

            System.out.println(xml);

    And here is the resulting generated XML:
    <list>
      <artist serialization="custom">
        <org.objectstyle.cayenne.CayenneDataObject>
          <int>3</int>
          <org.objectstyle.cayenne.ObjectId>
            <objectIdKeys class="java.util.Collections-SingletonMap">
              <k class="string">ARTIST_ID</k>
              <v class="int">1</v>
            </objectIdKeys>
            <objectClass>webtest.Artist</objectClass>
            <hashCode>-26571346</hashCode>
          </org.objectstyle.cayenne.ObjectId>
        </org.objectstyle.cayenne.CayenneDataObject>
      </artist>
      <artist serialization="custom">
        <org.objectstyle.cayenne.CayenneDataObject>
          <int>3</int>
          <org.objectstyle.cayenne.ObjectId>
            <objectIdKeys class="java.util.Collections-SingletonMap">
              <k class="string">ARTIST_ID</k>
              <v class="int">3</v>
            </objectIdKeys>
            <objectClass>webtest.Artist</objectClass>
            <hashCode>-26571344</hashCode>
          </org.objectstyle.cayenne.ObjectId>
        </org.objectstyle.cayenne.CayenneDataObject>
      </artist>
      <artist serialization="custom">
        <org.objectstyle.cayenne.CayenneDataObject>
          <int>3</int>
          <org.objectstyle.cayenne.ObjectId>
            <objectIdKeys class="java.util.Collections-SingletonMap">
              <k class="string">ARTIST_ID</k>
              <v class="int">4</v>
            </objectIdKeys>
            <objectClass>webtest.Artist</objectClass>
            <hashCode>-26571343</hashCode>
          </org.objectstyle.cayenne.ObjectId>
        </org.objectstyle.cayenne.CayenneDataObject>
      </artist>
      <artist serialization="custom">
        <org.objectstyle.cayenne.CayenneDataObject>
          <int>3</int>
          <org.objectstyle.cayenne.ObjectId>
            <objectIdKeys class="java.util.Collections-SingletonMap">
              <k class="string">ARTIST_ID</k>
              <v class="int">2</v>
            </objectIdKeys>
            <objectClass>webtest.Artist</objectClass>
            <hashCode>-26571345</hashCode>
          </org.objectstyle.cayenne.ObjectId>
        </org.objectstyle.cayenne.CayenneDataObject>
      </artist>
    </list>

    One of the advantages of our method is that you can use a mapping file so
    you have complete control over the resulting XML and potentially it is a lot
    cleaner. I think that other thing is that you lose the name of the
    relationship and it will harder to parse.

    I will look into the Xstream stuff further.

    -John

    On 5/12/05 10:29 AM, "Andrus Adamchik" <andru..bjectstyle.org> wrote:

    >> Andrus just mentioned the XML serialization feature..how far along is
    >> this? I ask because I recently used XStream
    >> (http://xtstream.codehaus.org/) and found it fantastically easy to use
    >> and also very fast. Just an idea..
    >>
    >> Holger
    >
    > This was developed by Kevin Menard and AFAIK this is still pretty unstable
    > (http://objectstyle.org/confluence/display/CAY/2005/03/09/).
    >
    > I need to check out xtstream. If it happens to be something usable and
    > easy to integrate with Cayenne, my vote would be to kill our own
    > implementation.
    >
    > Andrus
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Thu May 12 2005 - 13:54:02 EDT