繁体   English   中英

有没有一种方法可以配置JAXB插件为布尔型getter方法附加“ get”而不是“ is”

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

我在项目中使用了下面提到的JAXB插件

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

其中为布尔元素附加“ get”。 但是在迁移到新插件时

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

我对boolean型元素的getter方法“是”。 但是代码需要旧的签名。 例如

假设我们有以下类型为boolean元素。

a)fileCreated。

New Plugin在Generated列下生成了以下方法签名。我在Expected列下列出了期望的方法。

       Generated                           Expected
  boolean isFileCreated()             boolean getFileCreated()

我们的团队无法维护某些代码,因此更改调用代码不在我们手中。 请建议是否有一种配置此插件的方法,以便它像我们期望的那样为boolean生成getter。

提前致谢。

这是pom.xml内的JAXB插件配置

<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>

进行此更改后,我仍然得到“ is”附加的布尔类型的属性名称。

您可以在maven插件中使用enableIntrospection选项。 看这里

<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>

使用元素<xs:element minOccurs="0" name="flag" type="xs:boolean" />

<enableIntrospection>false</enableIntrospection>

生成的类public Boolean isFlag() {

代替

<enableIntrospection>true</enableIntrospection>

生成的类public Boolean getFlag() {

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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