Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As I understand you Ben the following XSD:</p> <pre><code>&lt;xs:element name="myElement" type="xs:string" nillable="true" minOccurs="0" /&gt; </code></pre> <p>Should result in:</p> <pre><code>@XmlElementRef(name = "myElement", namespace = "/mynamespace", type = JAXBElement.class, required = false) protected JAXBElement&lt;String&gt; myElement; </code></pre> <p>Right?</p> <p>But for default JAXB implementation it is not the case. Looks like a bug in JAXB. I didn't find it in JAXB <a href="https://java.net/jira/secure/IssueNavigator.jspa?reset=true&amp;jqlQuery=project+%3D+JAXB+AND+%28summary+~+%22XmlElementRef+AND+required%22+OR+description+~+%22XmlElementRef+AND+required%22%29" rel="nofollow">issue tracker</a>. <code>required</code> attribute was introduced to <code>@XmlElementRef</code> in JAXB 2.2 in around 2009 but apparently no one created issue for this problem.</p> <p><code>required</code> attribute cannot be changed using Binding Customizations.</p> <p>In this situation you can:</p> <ul> <li>write your own plugin for XJC to add missing attribute to <code>@XmlElementRef</code> annotation. It is not that difficult. More information <a href="https://jaxb.java.net/plugin.html" rel="nofollow">here</a>.</li> <li>use alternative JAXB implementation (MOXy works fine - <code>required = false</code> is generated using <a href="http://wiki.eclipse.org/EclipseLink/Examples/MOXy/JAXB/Compiler" rel="nofollow">MOXy JAXB compiler</a>)</li> <li>wait for Oracle implementation of JAXB to be fixed.</li> </ul> <p>No matter which option you choose please raise issue in <a href="https://java.net/jira/browse/JAXB/" rel="nofollow">JAXB issue tracker</a> so that the problem will be fixed.</p> <p><strong>EDIT:</strong></p> <p>To show that creating plugin is easy I created one. You can find it in my <a href="https://github.com/destin/SO-answers/tree/master/xjc-nullablenillable" rel="nofollow">github repository</a>. Feel free to use/copy/modify at will. I don't give guarantee that it works in 100% but for simple cases works like a charm.</p> <p><strong>EDIT2:</strong></p> <p>If schema generated based on java objects and JAXB annotations does not match your interface then you can use <code>@WebService.wsdlLocation</code> to point to your original, correct WSDL and XSD files.</p> <p><strong>EDIT3:</strong></p> <p>It's weird that <code>nil</code> is ignored by JAXB in your case. I ran a test using JAXB 2.2.6 and 2.2.7 and <code>nil</code> is correctly recognized:</p> <pre><code>JAXBContext context = JAXBContext.newInstance(SomeElement.class); Unmarshaller unmarshaller = context.createUnmarshaller(); String xml = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?&gt;&lt;ns2:someElement xmlns:ns2=\"http://www.example.org/example/\"&gt;&lt;myElement xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:nil=\"true\"/&gt;&lt;/ns2:someElement&gt;"; SomeElement someElement = (SomeElement) unmarshaller .unmarshal(new StringReader(xml)); assertThat(someElement.getMyElement().isNil(), is(true)); </code></pre> <p>Could you check whether you correctly set nil attribute, e.g.:</p> <pre><code>&lt;myElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/&gt; </code></pre> <p>If it is correct please try to run the test with your class.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

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