We've actually ended up writing our own serialiser and deserialiser based on a 
reflection excerpt from Better, Faster, Lighter Java by Bruce Tate and Justin 
Gehtland (pg 70 something). We combined this with the strategy pattern (one 
class per type of strategy (ie ArrayStrategy, Map, Collection, Bean, Primitive 
etc) with an isApplicable method which takes a class or class name and a 
process method wich does the (de)serialisation for that type of object). We 
added the ability to handle beans with references to another bean by passing 
around a context map containing all objects that had been (or were being) 
processed. We also added a type conversion function to each strategy because we 
are passing message between .Net client and java server. We then just passed 
the xml messages. 

It's a bit of work, but works well.

Code is unavailable, sorry, but the resulting xml looks something like this:

<item class=\"interop.array\" componentType=\"interop.object\" id=\"0\">
        <item class=\"interop.string-object\">My array</item>
        <item class=\"interop.array\" itemClass=\"interop.string-object\" 
id=\"1\">
                <item class=\"interop.string-object\">1</item>
                <item class=\"interop.string-object\">2</item>
        </item>
        <item class=\"ObjectWithReferences\" id=\"2\">
                <referenceObject class=\"ObjectWithReferences\" refid=\"2\"/>
        </item>
</item>

for this object:

Object[] arrayObject = new Object[]{"My array", new String[]{"1", "2"},
                                new ObjectWithReferences()};

ObjectWithReferences test class:

class ObjectWithReferences
{

        private ObjectWithReferences referenceObject = this;

        public ObjectWithReferences()
        {
                
        }

        /**
         * @param object
         * @return
         * 
         * @see java.lang.Object#equals(java.lang.Object)
         */
        public boolean equals(Object object)
        {
                if (!(object instanceof ObjectWithReferences)) return false;
                ObjectWithReferences them = (ObjectWithReferences) object;
                
                return (them.getReferenceObject() == them) && (referenceObject 
== this);
        }

        /**
         * @return
         * 
         * @see java.lang.Object#hashCode()
         */
        public int hashCode()
        {
                return super.hashCode();
        }

        /**
         * @return Returns the object1.
         */
        public ObjectWithReferences getReferenceObject()
        {
                return referenceObject;
        }

        /**
         * @param object1
         *                   The object1 to set.
         */
        public void setReferenceObject(ObjectWithReferences referenceObject)
        {
                this.referenceObject = referenceObject;
        }
}


-----Original Message-----
From: John Menke [mailto:[EMAIL PROTECTED]
Sent: Monday, 15 November 2004 11:06 AM
To: Axis
Subject: does anyone have complex serialization working?


Is it even possible to serialize an array of beans where the beans have
references to another bean?  Nobody has been able to come up with a working
example.  beanMapping is not working for me.  I have posted several times
and nothing... i'm beginning to think it's not possible.

-jm

Reply via email to