5

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.

user1414745
  • 1,317
  • 6
  • 25
  • 45
  • The following may help: http://stackoverflow.com/questions/19665550/jaxb-element-that-is-both-optional-and-nillable/19666240#19666240 – bdoughan Nov 19 '13 at 19:22

1 Answers1

0

use @XmlElement(nillable = true) in your Java Class

@XmlElement(nillable=true)
public String getAString() {
    return AString;
}

Refer to this Stack Overflow question/answer

Community
  • 1
  • 1
Dan Abel
  • 107
  • 1
  • 10
  • if only it were that straightforward ... when I use this notation, I will not be able to check if the attribute is true in my java code. That's why I used `@XmlElementRef` – user1414745 Nov 22 '13 at 21:09