users@jaxb.java.net

Is it possible to map an optional int element to a primitive int instead of an Integer?

From: stefcl <stefatwork_at_gmail.com>
Date: Thu, 16 Apr 2009 08:28:00 -0700 (PDT)

Hello :

I have the following in my xsd file :

<xsd:element name="quantity" default="1" minOccurs="0" >
                <xsd:simpleType >
                    <xsd:restriction base="xsd:int" >
                        <xsd:minInclusive value="1" />
                    </xsd:restriction>
                </xsd:simpleType>
            </xsd:element>


When I run xjc on this schema, the quantity property is considered nullable
and this results to
protected Integer quantity;

I'd like map it to a primitive int with a default value of 1, so that when
the element is unmarshalled, a default of 1 is assumed if the element
doesn't exist.

I have tried using the following binding customization:

<bindings schemaLocation="TransactionsSchema.xsd"
node="//xsd:element[@name='quantity']">
       <javaType name="java.lang.int"></javaType>
  </bindings>

XJC now generates an int property, but it also creates an Adapter1 class
file which I don't want. The default value problem isn't solved neither.

According to all the documentation I have read, the property declaration
which would meet all my expectations is :
protected int quantity = 1;

But I have no idea how to tell XJC to generate such a declaration, I know
there's a default value plugin which could help in the commons projects.
Unfortunately, plugins seems no longer usable with current version of jaxB
and jdk (they generate ClassCastException during instantiation).

Any help would be greatly appreciated... I have already wasted the whole day
trying to find a solution :(.

-- 
View this message in context: http://www.nabble.com/Is-it-possible-to-map-an-optional-int-element-to-a-primitive-int-instead-of-an-Integer--tp23080320p23080320.html
Sent from the java.net - jaxb users mailing list archive at Nabble.com.