I have just had this same problem of serializing/deserializing ArrayLists.
Amazingly after searching all through the lists and surfing the web, it
seemed like nobody had done it. I know that in Axis release it looks
possible, but for the moment I am tied into SOAP 2.2 so this isn't an
option.

In the end I wrote the serializer/deserializer myself, - I'll paste java
code in below. Note that my class ObjectList extends ArrayList, so for a
pure serializer of ArrayList just replace all references of ObjectList with
ArrayList and it should work fine.

cheers, Joe.



public class ObjectListSerializer implements Serializer, Deserializer {

  public void marshall(String inScopeEncStyle, Class javaType, Object src,
                       Object context, Writer sink, NSStack nsStack,
                       XMLJavaMappingRegistry xjmr, SOAPContext ctx)
    throws IllegalArgumentException, IOException {

      nsStack.pushScope();
      if ((src != null) &&
                  !(src instanceof ObjectList)) {
          throw new IllegalArgumentException("Tried to pass a '" +
                          src.getClass().toString() + "' to
ObjectListSerializer");
      }
      Iterator it;
      ObjectList objList = (ObjectList)src;
      it = objList.iterator();
      if (src == null) {

SoapEncUtils.generateNullStructure(inScopeEncStyle,javaType,context,sink,
                                       nsStack,xjmr);
      }
      else {

SoapEncUtils.generateStructureHeader(inScopeEncStyle,javaType,context,
                                         sink,nsStack,xjmr);
        sink.write(StringUtils.lineSeparator);
        for (Iterator i = it; i.hasNext(); ) {
          nsStack.pushScope();
          Object value = i.next();
          if (value == null) {
            SoapEncUtils.generateNullStructure(inScopeEncStyle,
Object.class,
                                               "item", sink, nsStack, xjmr);
          }
          else {
            Class actualComponentType = value.getClass();
            xjmr.marshall(inScopeEncStyle, actualComponentType, value,
"item",
                          sink, nsStack, ctx);
          }
          sink.write(StringUtils.lineSeparator);
          nsStack.popScope();
        }
        sink.write("</" + context + '>');
      }
      nsStack.popScope();
    }

    public Bean unmarshall(String inScopeEncStyle, QName elementType, Node
src,
                           XMLJavaMappingRegistry xjmr, SOAPContext ctx)
      throws IllegalArgumentException  {
            Element root = (Element)src;
            if (SoapEncUtils.isNull(root)) {
                return new Bean(ObjectList.class, null);
            }
            ObjectList objList = new ObjectList();
            Element tempEl = DOMUtils.getFirstChildElement(root);
            while (tempEl != null) {
                String declEncStyle =
DOMUtils.getAttributeNS(tempEl,Constants.NS_URI_SOAP_ENV,

Constants.ATTR_ENCODING_STYLE);
                String actualEncStyle = declEncStyle != null
                                                                ?
declEncStyle
                                                                      :
inScopeEncStyle;
                QName declItemType = SoapEncUtils.getTypeQName(tempEl);
                QName actualItemType = declItemType;

                Bean itemBean = xjmr.unmarshall(actualEncStyle,
actualItemType, tempEl, ctx);
                objList.add(itemBean.value);
                tempEl = DOMUtils.getNextSiblingElement(tempEl);
            }
            return new Bean(ObjectList.class, objList);
    }
}
// end of class

----- Original Message -----
From: Rose, Angus H <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, August 16, 2002 8:34 AM
Subject: RE: Serializer probs..


> I thought of that, but I'm just surprised that arraylists aren't
supported.
> Thanks for you help though
>
> Angus
>
> -----Original Message-----
> From: Tudor, Liviu @Cimage [mailto:[EMAIL PROTECTED]]
> Sent: 15 August 2002 16:28
> To: '[EMAIL PROTECTED]'
> Subject: RE: Serializer probs..
>
>
> Serialize it as a normal array! (i.e. in your bean provide a property that
> has a get/set pair returning an array rather than an array list! )
>
> Liviu Tudor
>
> Cimage Novasoft Limited
> : www.cimagenovasoft.com <http://www.cimagenovasoft.com/>
> + [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>
> (Fax: +44 (0)1344 767701
> (Direct Line: +44 (0)1344 767759
> *Centennial Court, Easthampstead Road, Bracknell, BERKS, RG12 1JZ
>
>  Sun Java Certified Programmer
> "C makes it easy to shoot yourself in the foot; C++ makes it harder, but
> when you do, it blows away your whole leg." Bjarne Stroustrup
>
>
>
> -----Original Message-----
> From: Rose, Angus H [mailto:[EMAIL PROTECTED]]
> Sent: 15 August 2002 16:24
> To: Soap-User (E-mail)
> Subject: Serializer probs..
>
>
> Hello All,
>              once again I need somebody's help - thank God for user lists.
>
> Basically, I'm trying to pass an ArrayList back from a service, and get
this
> error message:
> ' Ouch, the call failed:
>  Fault Code = SOAP-ENV:Server
>  Fault String = java.lang.IllegalArgumentException: No Serializer found to
> serialize a 'java.util.ArrayList' using encoding style
> 'http://schemas.xmlsoap.org/soap/encoding/'.'
>
> Any suggestions?
>
> Thanks in advance
>
> Angus
>
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
>
> --
> To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to