Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok this is how I've made it work:</p> <pre><code>import java.util.List; import java.util.Map; import javax.xml.bind.annotation.XmlAnyAttribute; import javax.xml.bind.annotation.XmlAnyElement; import javax.xml.bind.annotation.XmlType; import javax.xml.namespace.QName; import org.w3c.dom.Element; public class SchemaExtensible { @XmlAnyElement(lax=true) private List&lt;Element&gt; otherElements; @XmlAnyAttribute private Map&lt;QName,Object&gt; otherAttributes; } </code></pre> <p>It's not ideal because now I have to extend this class for every response class that I want to be extensible (and in some cases this stops me from extending from a request class instead). If these 2 method &amp; field level annotations could be enhanced to allow them to be added at the class level then they could simply be saying "add the appropriate tags to the schema and just throw away the data if encountered" which would be sweet.</p> <p>Any way the schema fragment ends up looking like this:</p> <pre><code>&lt;xs:complexType name="SchemaExtensible"&gt; &lt;xs:sequence&gt; &lt;xs:any processContents="lax" namespace="##other" minOccurs="0" maxOccurs="unbounded"/&gt; &lt;/xs:sequence&gt; &lt;xs:anyAttribute namespace="##other" processContents="skip"/&gt; &lt;/xs:complexType&gt; </code></pre> <p>For me, allowing this extensibility for response objects only is preferable to web service versioning as it allows you to evolve the schema bit by bit, if you so desire, without the headache of managing many different versions, and without the worry that any existing clients will break if you add a single new attribute or element to a response object.</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