• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about JAXB data type mapping for positiveInteger

 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
I am not a spy. Definitely. Definitely not a spy. Not me. No way. But this tiny ad ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic