SOAP Object Serialization in Java

Ethan Reesor picture Ethan Reesor · Jun 7, 2012 · Viewed 8.3k times · Source

I am using JBoss AS 7.1.1 and JAX-WS 2.0.

In my application, I need to pass a Map<String, Map<String, String>> to a service. I made a custom complex type which extends TreeMap. While debugging, I confirmed that the object I was trying to sent was filled with data, but the received object was empty. From other posts, it seems this is because does not play well with SOAP serialization. Is there some way I can implement SOAP XML serialization for my object without changing types, making a ton of fields, etc? I want to be able to the following:

public String doSoapXmlSerialization() {
    // code
}
public void doSoapXmlDeserialization() {
    // code
}

It would be a very simple matter for me to write serialization and deserialization methods. I can also imagine writing some kind of XSD file to allow the SOAP methods to do my work for me. I have not been able to find any guides for this. By what mechanism does JAX-WS try to serialize objects?.

Answer

Ethan Reesor picture Ethan Reesor · Jul 30, 2012

I realized that the section (of my WSDL file) describing the send and receive objects was an XML Schema, and that SOAP uses JAXB. I followed this guide and built a schema. This allowed me to create whatever I wanted.

Related:

JAXB: how to marshall map into <key>value</key>