Note that there are some explanatory texts on larger screens.

plurals
  1. POMarshalling polymorphic objects in JAX-WS
    text
    copied!<p>I'm creating a JAX-WS type webservice, with operations that return an object WebServiceReply. The class WebServiceReply itself contains a field of type Object. The individual operations would populate that field with a few different data-types, depending on the operation.</p> <p>Publishing the WSDL (I'm using Netbeans 6.7), and getting a ASP.NET application to retrieve and parse the WSDL was fine, but when I tried to call an operation, I would receive the following exception:</p> <pre><code>javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException - with linked exception: [javax.xml.bind.JAXBException: class [LDataObject.Patient; nor any of its super class is known to this context.] </code></pre> <p>How do I mark the annotations in the DataObject.Patient class, as well as the WebServiceReply class to get it to work? I haven't been able to fine a definitive resource on marshalling based upon annotations within the target classes either, so it would be great if anybody could point me to that too.</p> <h2>WebServiceReply.java</h2> <pre><code>@XmlRootElement(name="WebServiceReply") public class WebServiceReply { private Object returnedObject; private String returnedType; private String message; private String errorMessage; .......... // Getters and setters follow } </code></pre> <h2>DataObject.Patient.java</h2> <pre><code>@XmlRootElement(name="Patient") public class Patient { private int uid; private Date versionDateTime; private String name; private String identityNumber; private List&lt;Address&gt; addressList; private List&lt;ContactNumber&gt; contactNumberList; private List&lt;Appointment&gt; appointmentList; private List&lt;Case&gt; caseList; } </code></pre> <hr> <h2>Solution</h2> <p>(Thanks to <a href="https://stackoverflow.com/questions/1163795/marshalling-polymorphic-objects-in-jax-ws/1164187#1164187">Gregory Mostizky</a> for his answer)</p> <p>I edited the WebServiceReply class so that all the possible return objects extend from a new class ReturnValueBase, and added the annotations using @XmlSeeAlso to ReturnValueBase. JAXB worked properly after that!</p> <p>Nonetheless, I'm still learning about JAXB marshalling in JAX-WS, so it would be great if anyone can still post any tutorial on this.</p> <p>Gregory: you might want to add-on to your answer that the return objects need to sub-class from ReturnValueBase. Thanks a lot for your help! I had been going bonkers over this problem for so long! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload