for the request for my web service, I wanted to differ between requested null
value and missing tag. In other words I needed the following element definition:
<xs:element minOccurs="0" name="minzeronil" nillable="true" type="xs:string"/>
I developed the web service code-first, so I defined the element using JAXBElementRef
:
@XmlRegistry
public class ObjectFactory {
@XmlElementDecl(name = "minzeronil", namespace = XmlNamespace.MY_SERVICE)
public JAXBElement<String> createMinzeronil(final String value) {
return new JAXBElement<String>(new QName(XmlNamespace.MY_SERVICE, "minzeronil"), String.class, value);
}
}
Now, I expected to see nillable = "true"
in the definition of the element. Instead, I got:
<xs:element name="minzeronil" type="xs:string"/>
<xs:element ref="tns:minzeronil" minOccurs="0"/>
How can I generate nillable = "true"
from my java code? ... and still use JAXBElement in my code and its methods like isNil()
...
UPDATE: I deploy the code on glassfish, so glassfish is the one that generates the wsdl and xsd.
use @XmlElement(nillable = true)
in your Java Class
@XmlElement(nillable=true)
public String getAString() {
return AString;
}
Refer to this Stack Overflow question/answer