You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Marc Wilson <sc...@hotmail.com> on 2004/07/28 04:46:07 UTC

Advanced serialization of Collections and Maps

Hi,

I have a few questions about serialization and deserialization of 
Collections and Maps with Axis.

Basically our app has a Business Object Model of DTOs (Data Transfer 
Objects) that it relatively complex from a Soap p.o.v., ie: it contains 
lists, sets and maps within it. All the lists, sets and maps in the BOM 
contain elements of one type only.

We are evaluating the practicallity of exposing the API of our application 
(currently accessed through Stateless Session EJBs) also as a WebService 
through AXIS.

I have got it working for "simple" return values, but for complex return 
values as I expected it doesn't work as easily.

What I want to be able to do is use the serialization and deserialization 
abilities of Axis to serialise any and all Collections in the return values 
as typed arrays (I'll get to maps in a minute).

I think that the BeanSerializer can currently serialize a List as 
xsd:anyType[] or soapenc:Array, but I need it to be typed when it is 
serialized so that any client can generate everything it needs from the wsdl 
and not have to worry about any complex mappings etc..

I plan to markup the DTOs and use xDoclet and to generate custom 
serialization and deserialization classes:
ie:
----------------------------------------
class MouseDTO
{
    /**
     * @mymarkuptag.list type=Cat
     */
    public List getCats() ...

    /**
     * @mymarkuptag.set type=Dog
     */
    public Set getDogs() ...
}
class CatDTO
{
    ..
}
class DogDTO
{
    ..
}
----------------------------------------
would generate
----------------------------------------
class FooDTOSerialiser extends MyCollectionSerializer
{
    FooDTOSerialiser()
    {
        super(new String[]{"cats","dogs"}, new Class[]{CatDTO.class, 
DogDTO.class});
    }
}
----------------------------------------

Then I plan to write a MyCollectionSerializer base class which will act like 
the current BeanSerializer (probably will extend it) but for the properties 
that were specified in the constructor (ie: cats) it will do the 
serialisation as if it were an array of that type (ie: CatDTO[]).

Maps would work the same way except that there would be two classes marked 
up for the key and value types and they would be serialised as an array of a 
type that contains the key and value types (ie: TypeATypeBPair[], where 
TypeATypeBPair is { TypeA key, TypeB value}).

Now, the questions:

Does what I want to do make sense?

Is there anything out in Axis land that does this already?

Does anyone have any ideas/input into how I would/should write the base 
serializer classes?

Any other ideas of feedback would be appreciated

Cheers
-Marc

_________________________________________________________________
SEEK: Now with over 50,000 dream jobs! Click here:   
http://ninemsn.seek.com.au?hotmail