简体   繁体   中英

Is there a way to configure JAXB plugin to append “get” for boolean getter method instead of “is”

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.

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() {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM