• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Question about JAXB data type mapping for positiveInteger

Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.

1. The XML Schema specification clearly states that "The ·value space· of positiveInteger is the infinite set {1,2,...}"
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!

R Srini
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

Goodbye moon men. Hello tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic