This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Services Certification (SCDJWS/OCEJWSD) and the fly likes Question about JAXB data type mapping for positiveInteger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "Question about JAXB data type mapping for positiveInteger" Watch "Question about JAXB data type mapping for positiveInteger" New topic
Author

Question about JAXB data type mapping for positiveInteger

R Srini
Ranch Hand

Joined: Feb 19, 2010
Posts: 215
Hi,

Per a JAXB Wiki, the positiveInteger XSD datatype maps to Java's BigInteger datatype.

I am trying out different data types (allowed in XML Schemas) to see the generated code. And I am using xjc from NetBeans to generate Java code for the schema.

And for this element:

xjc generates this code:
Now I started questioning this because for a positive integer, I was thinking that the generated code would actually check that the integer is positive, and if not, then I was expecting that it would throw an exception.

So I went ahead and ran a simple client, and observed these results:

a) When I put in a negative value in the XML data file and unmarshal it, it works without throwing an exception (which I was expecting)
b) When I add a negative value and marshal it to XML, there is still no exception.

Now:
1. The XML Schema specification clearly states that "The ·value space· of positiveInteger is the infinite set {1,2,...}"
However:
2. The xjc-generated code does not check whether the number is positive, and
3. Neither does the marshalling and unmarshalling infrastructure in javax.xml.bind check for the sign

Question: So what is going on? Is this how it is supposed to work or am I missing some important step or configuration setting or xjc option in the process?

Thanks in advance for your help!

Srini
R Srini
Ranch Hand

Joined: Feb 19, 2010
Posts: 215
Ok. I guess I have to set the marshaller and unmarshaller to "validate" the xml data. In JDK 1.6, I used:


Now I get the exception that I was expecting earlier:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Question about JAXB data type mapping for positiveInteger
 
Similar Threads
Annotation for regular expression.
Facade design pattern in web services
JaxB Class Declaration Imports
General question on JAXB annotations generated when using xjc
Calling a ColdFusion Web Service method