【发布时间】:2021-07-18 12:37:16
【问题描述】:
我正在从 WSDL 生成源代码。它生成包装器类型。我希望 JAXB 生成原始类型而不是包装器。
在 pom.xml 中
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.5.0</version>
<executions>
<execution>
<id>generate-stubs</id>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<sourceType>wsdl</sourceType>
<sources>
<source>
${project.basedir}/src/main/resources/wsdl/my.wsdl
</source>
</sources>
<clearOutputDir>true</clearOutputDir>
</configuration>
</execution>
</plugin>
在我的 WSDL 文件中
<xs:element minOccurs="0" name="initBal" type="xs:long"/>
在生成的类中
protected Long initBal;
我试图设置一个 bindingDirectory 来强制使用原语而不是包装器。但似乎该选项不适用于 jaxb2-maven-plugin 2.5.0 版本。
<configuration>
<sourceType>wsdl</sourceType>
<sources>
<source>
${project.basedir}/src/main/resources/wsdl/my.wsdl
</source>
</sources>
<clearOutputDir>true</clearOutputDir>
<xjbSources>
<xjbSource>${project.basedir}/src/main/resources/wsdl/aBindingConfiguration.xjb</xjbSource>
</xjbSources>
</configuration>
aBindingConfiguration.xjb 文件
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.1">
<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
</jaxws:bindings>
</jaxb:bindings>
【问题讨论】:
-
查看mojohaus.org/jaxb2-maven-plugin/Documentation/v2.5.0/… 以获取可用配置。并且 bindingDirectory 未列出。
-
bindingDirectory 似乎在 2.x 中不可用,替代选项不清楚
-
您使用 bindingDirectory 的目的是什么?
-
我假设您之前没有在 Stackoverflow 上搜索过您的问题。因为我在另一个 Stackoverflow 问题中找到了您的答案。 stackoverflow.com/questions/13801401/… 通过寻找 jaxb 生成原语。您必须删除 minOccurs="0" 这表示一个可以为空的值。
-
您不能将原始类型用于可空值,因为原始类型不可为空。
标签: java jaxb jaxb2-maven-plugin