hevi
hevi

Reputation: 2726

Jaxb creating boolean method accessor names with "get" instead of "is" prefix

Using jaxb2-maven-plugin and jaxb-xjc, while generating classes jaxb creates boolean accessors with get prefix however I want it to create with java convention "is".

here is the xsd:

    <xsd:complexType name="QueryWorkgroupRequestType">
    <xsd:sequence>
    ...
        <xsd:element name="disabled" type="xsd:boolean" minOccurs="0" maxOccurs="1" />
    ...
    </xsd:sequence>
</xsd:complexType>

and the created method is;

public Boolean getDisabled() {
    return disabled;
}

But I want instead;

public Boolean isDisabled() {
    return disabled;
}

I tried

<xsd:annotation> <xsd:appinfo> <jaxb:globalBindings enableJavaNamingConventions="true" generateIsSetMethod="true"/> </xsd:appinfo> </xsd:annotation> but no chance.

** SOLVED **

Well at last I could sort out the problem, maven was using jdk 1.8, somehow using 1.8 masses it up. Using 1.6 fixed it, works as desired now.

Upvotes: 5

Views: 4326

Answers (1)

Ian Roberts
Ian Roberts

Reputation: 122414

The is prefix for Java Bean accessor methods is only valid for properties of the primitive type boolean. For all other types (including the java.lang.Boolean reference type) the only valid prefix that will be recognised as a bean property accessor is get.

If the element were not nullable (i.e. it didn't have minOccurs="0") then it would be bound to a property of type boolean rather than Boolean and would get an is accessor.

Upvotes: 8

Related Questions