Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 1000
hevi Avatar asked Jan 20 '15 17:01

hevi


1 Answers

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.

like image 121
Ian Roberts Avatar answered Oct 28 '22 05:10

Ian Roberts