users@jaxb.java.net

Re: xs:int and getter return types

From: Lucas Madar <lucas_at_mcsnw.com>
Date: Tue, 21 Jul 2009 09:21:15 -0700

This is not what is being generated by the current version of XJC. I'm
using 2.1.12 (as of this morning) and getting the invalid results. I
have JDK 1.6.0_13. I downgraded to 2.1.3 and I am obtaining the same
results as well (build #382).

This is the tag given at the top of the file: // This file was generated
by the JavaTM Architecture for XML Binding(JAXB) Reference
Implementation, vhudson-jaxb-ri-2.1-833

It appears that this behavior only exists for attributes. Elements that
are typed as xs:int use Integer as a getter/setter type, unless they
have a minOccurs of 1, where they use int all the way through.

- Lucas

On 7/21/2009 4:40 AM, Wolfgang Laun wrote:
> vJAXB 2.1.3 in JDK 1.6.x and later versions of xjc generate
>
> public int getInheritedCount() {
> if (inheritedCount == null) {
> return 0;
> } else {
> return inheritedCount;
> }
> }
>
> which is OK.
>
> -W
>
> On Tue, Jul 21, 2009 at 12:06 AM, Lucas Madar <lucas_at_mcsnw.com
> <mailto:lucas_at_mcsnw.com>> wrote:
>
> Hello,
>
> I have an schema segment that looks like this:
>
> <xs:attribute name="inheritedCount" type="xs:int" use="optional">
>
> It generates code like this:
>
> @XmlAttribute(name = "inheritedCount")
> protected Integer inheritedCount;
>
> public int getInheritedCount() {
> return inheritedCount;
> }
>
> So, when getInheritedCount() is called, a NullPointerException is
> thrown when Java autoboxes Integer->int.
>
> Is there anyway to force JAXB/XJC to use Integer as a return type
> for xs:int?
>
> Thanks,
> Lucas Madar
>
>