javax.xml.bind.MarshalException - with linked exception: [javax.xml.bind.JAXBException: class ** nor any of its super class is known to this context

Viewed 27178

I have a generic web service which is expecting a WebServiceRequest object. This object has a payload which is of type Object. Below is the type of my payload.

<xs:complexType name="payload">
    <xs:sequence>
        <xs:any processContents="lax"></xs:any>
    </xs:sequence>
</xs:complexType>

I created JAXB classes for the web service input and output types. So for payload, this the field that was generated.

 @XmlAnyElement(lax = true)
 private Object any;

Below is the structure of my JAXB generated WebServiceRequest VO.

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "serviceRequest", namespace = "http://ws.test.svc.com/", propOrder = {
    "payload"
})
public class WebServiceRequest{
        @XmlElement
        private Payload payload;
} 

public class Payload{
 @XmlAnyElement(lax = true)
 private Object any;
}

I have some custom POJOs which I need to populate and set as the payload. I annotated these POJOs using the following annotation

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class AddressVO {
    @XmlElement
    private String pinCode;
    @XmlElement
    private String city;
}

I populated the data for this POJO and tried to set as the payload of WebServiceRequest. But when I do that, I'm getting the below exception.

javax.xml.bind.MarshalException
 - with linked exception:
[javax.xml.bind.JAXBException: class com.vo.test.AddressVO nor any of its super class is known to this context.

Could you please suggest some ways to overcome this? In one link it was mentioned to include @XmlSeeAlso, but i can't do that since my payload is very generic. Kindly help me in this regard.

1 Answers
Related