users@jaxb.java.net

Changing JAXB's optional + nillable code generation default behaviour

From: <renrutal_at_gmail.com>
Date: Wed, 12 Sep 2012 15:21:51 +0000 (GMT)

I'm looking for a way to change the default behaviour of generating
Java code from a XML Schema, using an external bindings file, so that
instead of generating @XmlElement(nillable = true) and the object or
simple type wrapper, it will only generate the latter.

Example:

Using maven, and the wsimport plugin, I import a wsdl file, which is
linked to this xml schema:

<xs:complexType name="Person">
  <xs:sequence>
     <xs:element name="id" type="xs:long" minOccurs="0"
nillable="true"/>
     <xs:element name="birthDate" type="xs:dateTime" minOccurs="0"
nillable="true"/>
     <xs:element name="department" type="tns:Department" minOccurs="0"
nillable="true"/>
  </xs:sequence>
</xs:complexType>

So along with <jaxb:globalBindings generateElementProperty="false" />
in jaxb.xml

Today its currently generating

public class Person
{
    @XmlElement(nillable = true)
    protected Long id;
    @XmlElement(nillable = true)
    @XmlSchemaType(name = "dateTime")
    protected XMLGregorianCalendar birthDate;
    @XmlElement(nillable = true)
    protected Department department;
    (...)
}

I'd like to generate:

public class Person
{
    protected Long id;
    @XmlSchemaType(name = "dateTime")
    protected XMLGregorianCalendar birthDate;
    protected Department department;
    (...)
}

I want to do that for all the xml schema elements with both those
minoccurs=0 and nillable=true attributes, not only that Person schema.

Is there a way to do that only with JAXB's binding file, or do I need
to use an extension from an implementation, or maybe develop my own
SOAP Handler Chain or JAXB plugin?

I've seen many articles, a bit of the specification, but I can't think
of any way alter the generation of the nillable annotation. The closest
I've got is this article:
http://victor-ichim.blogspot.com/2011/03/hacking-minoccurs-and-nillable
.html where the author says it can't be done.