JAXB Generation nillable = true

Using JAXB 2.2.4 I generate Java code with the following binding file:

<bindings xmlns="http://java.sun.com/xml/ns/jaxb" version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <globalBindings generateElementProperty="false"> </globalBindings> 

Unfortunately, the generated code has the annotation nillable = true. See the following example:

 @XmlElement(name = "ArtID", nillable = true) protected STEBeitrag artID; 

This is the definition of STEBeitrag:

 <xsd:complexType name="CT_Beitrag"> <xsd:complexContent> <xsd:extension base="allgemein:CT_Objekt"> <xsd:sequence> <xsd:element name="ArtID" type="daten:STE_Beitrag" minOccurs="0" maxOccurs="1" nillable="true"/></xsd:element> </xsd:sequence> </xsd:extension> </xsd:complexContent> </xsd:complexType> 

 <xsd:complexType name="STE_Beitrag" abstract="true"> <xsd:simpleContent> <xsd:extension base="xsd:string"/> </xsd:simpleContent> </xsd:complexType> 

If I do not set the ArtID in the generated CT_Beitrag object, then the marshaller produces output, for example

 <ns:ArtID xsi:nil="true"/> 

The ArtID element has an abstract type, so this XML output is not valid.

How can I generate code with JAXB that omits nillable = true in the XmlElement annotation? By the way, the circuit cannot be changed.

+4
source share
2 answers

I have no solution, but this problem is resolved in the error http://java.net/jira/browse/JAXB-890 I hope this problem is resolved.

+1
source

I do not do what you ask, and I would be surprised if what you ask is worth the effort.

There are two options that fit my mind:

  • Change the scheme (I know that you said that you can’t, but maybe you can take a local copy of the scheme if you can’t change it because it is located on the server out of your control).
  • Change the generated code ... just change nillable=true to nillable=false
0
source

All Articles