Search code examples
javaserializationapache-axis

Axis client side serializer/deserializer


I have an array MyBean sent over the wire from my server side Axis web service. I got the serialisation working on the client side by adding

<beanMapping qname="MyBean" xmlns:ns="myns.MyBeanService"
                 languageSpecificType="java:myns.Appartment"/>

Now I get No deserializer for {myns.MyBean}MyBean on the client side. How can I tell the client to use the default BeanSerializer and BeanDeserializer since there is no server-config.wsdd ?


Solution

  • (source p51) In the client side class MyServiceSoapBindingStub, right after

    org.apache.axis.client.Call _call = createCall();
    

    add

    QName qn = new QName("myns.MyBeanService", "MyBean");
    
    call.registerTypeMapping(MyBean.class, qn,
            new BeanSerializerFactory(cl, qn),
            new BeanDeserializerFactory(cl, qn));
    

    This requires the client having a copy of MyBean.java.

    Also, if MyBean has sub beans, the same code should be added for all sub beans. It is handy to define a utils class like this:

    public final class WSUtils {
    
        public static void handleSerialization(Call call, String ns, String bean, Class cl) {
    
            QName qn = new QName(ns, bean);
    
            call.registerTypeMapping(cl, qn,
                    new BeanSerializerFactory(cl, qn),
                    new BeanDeserializerFactory(cl, qn));
        }
    }
    

    that can be used after the createCall() like this:

    WSUtils.handleSerialization(_call, "myns.MyBeanService", "MyBean", MyBean.class);
    

    and for sub beans:

    WSUtils.handleSerialization(_call, "myns.MyBeanService", "MySubBean", MySubBean.class);