4

I was using the below mentioned JAXB plugin in my project

<groupId>com.sun.tools.xjc.maven2</groupId>
<artifactId>maven-jaxb-plugin</artifactId>
<version>1.1.1</version>

Which appends "get" for boolean element. But on migrating to new plugin

<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.12.3</version>

I get "is" to the getter method for boolean type elements. But the code expects the old signature. For example

Suppose, we have following elements of type boolean.

a) fileCreated.

New Plugin has generated the following method signature under Generated column.I have listed the expected method under Expected column.

       Generated                           Expected
  boolean isFileCreated()             boolean getFileCreated()

There is some pieces of code which is not maintained by our team so changing calling code is not in our hands. Please suggest if there is a way to configure this plugin so that it generates the getter for boolean as we expect it to be.

Thanks in advance.

Here is the JAXB plugin configuration inside pom.xml

<plugin>
                    <groupId>org.jvnet.jaxb2.maven2</groupId>
                    <artifactId>maven-jaxb2-plugin</artifactId>
                    <version>0.12.3</version>

                    <executions>
                        <execution>
                            <id>kyc</id>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <configuration>

                            <!-- Added for generating getter for boolean element in XSDs with prefix "get"    starts-->
                            <enableIntrospection>true</enableIntrospection>

                            <!-- Added for generating getter for boolean element in XSDs with prefix "get"    ends-->



                                <generatePackage>XXX.XXX.APackage</generatePackage>
                                <schemaDirectory>src/main/resources/XXX/</schemaDirectory>
                                <generateDirectory>${project.build.directory}/generated-sources/XXX/generateDirectory>
                                <verbose>true</verbose>
                            </configuration>
                        </execution>
    </executions>
    </plugin>

After making this change, i am still getting "is" appended property name of type boolean.

Developer
  • 534
  • 1
  • 11
  • 21
  • 1
    See here: http://stackoverflow.com/questions/202124/getter-for-boolean-properties-with-jaxb – Jens Sep 05 '16 at 12:26

1 Answers1

3

You could use enableIntrospection option in maven plugin. See Here

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.12.3</version>
    <executions>

        <execution>
            <id>xjc1</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>generate</goal>
            </goals>
            <configuration>
                <args>
                    <arg>-Xannotate</arg>
                    <arg>-nv</arg>
                    <arg>-Xnamespace-prefix</arg>
                </args>
                <extension>true</extension>
                <schemas>
                    <schema>
                        <fileset>
                            <directory>${basedir}/src/main/resources/schema</directory>
                            <includes>
                                <include>*.xsd</include>
                            </includes>
                        </fileset>
                    </schema>
                </schemas>

                <enableIntrospection>true</enableIntrospection>

                <debug>true</debug>
                <verbose>true</verbose>
                <plugins>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics</artifactId>
                        <version>0.6.0</version>
                    </plugin>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-basics-annotate</artifactId>
                        <version>0.6.0</version>
                    </plugin>
                    <plugin>
                        <groupId>org.jvnet.jaxb2_commons</groupId>
                        <artifactId>jaxb2-namespace-prefix</artifactId>
                        <version>1.1</version>
                    </plugin>
                </plugins>
            </configuration>
        </execution>
    </executions>
</plugin>

using an element <xs:element minOccurs="0" name="flag" type="xs:boolean" />

<enableIntrospection>false</enableIntrospection>

generated class public Boolean isFlag() {

instead

<enableIntrospection>true</enableIntrospection>

generated class public Boolean getFlag() {

Xstian
  • 8,184
  • 10
  • 42
  • 72
  • @Developer the documentation says " If true, enables correct generation of Boolean getters/setters to enable Bean Introspection apis. Since 0.9.0" [Link](https://github.com/highsource/maven-jaxb2-plugin/wiki/Controlling-the-Output) – Xstian Sep 06 '16 at 12:03
  • I understood. I'm trying to say that using `true` works as you want. I update my answer. – Xstian Sep 06 '16 at 12:20
  • @Developer I found only a typo issue on following line `${project.build.directory}/generated-sources/XXX/generateDirectory>` because missing close tag. I tried your configuration and works fine it is generating `get` instead of `is`. – Xstian Sep 07 '16 at 12:23