0

I generated a set of classes with apache cxf based on a big wsdl we got from our client. It uses an anyType to let it contain a whole bunch of different types. This is the wsdl

<complexType name="PayloadBase">
    <complexContent>
        <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
        </restriction>
    </complexContent>
</complexType>

This translates in the following java code

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "PayloadBase")
public class PayloadBase {

    // empty as you can see

}

It turns out that any class that desires to use a child of this class doesnt know how to work with it. Say, for example, a subclass of PayloadBase is added to a wrapping object that also contains a timestamp, the following XML is generated

<bericht timestamp="2012-02-14T16:03:34.331+01:00"><payload/></bericht>

This is the result of sending the following class through the webservice code

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "BerichtDescription", propOrder = {
    "payload"
})
public class BerichtDescription {

    @XmlElement(required = true)
    protected PayloadBase payload;
    @XmlAttribute(name = "timestamp", required = true)
    @XmlSchemaType(name = "dateTime")
    protected XMLGregorianCalendar timestamp;

Any instance of PayloadBase used will never show in the resulting xml. I have verified with the debugger that the PayloadBase instance is indeed filled with content. How do I get java webservices to work with this setup?

Eric
  • 347
  • 1
  • 3
  • 11
  • I think, [this reply](http://stackoverflow.com/a/4305288/267197) is right direction. If you need complete solution, provide two XML samples with different payloads in your question. – dma_k Feb 18 '12 at 12:57

1 Answers1

1

It took me a while to figure out, but in the end the trick was to add @XmlSeeAlso annotation to the PayloadBase class for every subclass.

Eric
  • 347
  • 1
  • 3
  • 11