wsimport 生成带下划线的字母数字枚举
wsimport generating alphanumeric enum with underscore
使用 wsimport 从 WSDL 生成 java 类 时枚举名称正在更改:
pom.xml
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<configuration>
<wsdlLocation>http://localhost/service/*</wsdlLocation>
<wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
<xdebug>true</xdebug>
<verbose>true</verbose>
<target>2.0</target>
<keep>true</keep>
</configuration>
<executions>
<execution>
<id>PaymentCheck</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<packageName>com.pay.jaxws.paymentCheck</packageName>
<wsdlDirectory>${basedir}/src/main/resources/wsdl/internal</wsdlDirectory>
<wsdlFiles>
<wsdlFile>PaymentCheck.wsdl</wsdlFile>
</wsdlFiles>
</configuration>
</execution>
</executions>
</plugin>
WSDL 枚举描述为:
<schema> ....
<simpleType name="subFailureType">
<restriction base="string">
<enumeration value="SUCCESS"/>
<enumeration value="FA01" /> <!-- Failure code for - Not enough cover -->
<enumeration value="FA01" /> <!-- Failure code for - All other cases -->
</restriction>
</simpleType>
</schema>
生成Class:
@XmlType(name = "subFailureType")
@XmlEnum
public enum SubFailureType {
SUCCESS("SUCCESS"),
@XmlEnumValue("FA01")
FA_01("FA01"),
@XmlEnumValue("FA02")
FA_02("FA02");
private final String value;
SubFailureType(String v) {
value = v;
}
public String value() {
return value;
}
public static SubFailureType fromValue(String v) {
for (SubFailureType c: SubFailureType.values()) {
if (c.value.equals(v)) {
return c;
}
}
throw new IllegalArgumentException(v);
}
}
代替枚举 FA01/FA02 附加下划线 "FA_01" 出现在名称中。
有什么办法可以纠正这个问题吗?它与 2012 年提出的问题 wsimport generating enum types incorrectly with extra underscore 类似,没有找到任何解决方法或解决方案。
可以使用绑定解决这个问题,在pom.xml中添加了绑定条目:
<configuration>
<packageName>com.pay.jaxws.paymentCheck</packageName>
<wsdlDirectory>${basedir}/src/main/resources/wsdl/internal</wsdlDirectory>
<wsdlFiles>
<wsdlFile>PaymentCheck.wsdl</wsdlFile>
</wsdlFiles>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/wsdl/internal/paymentCheckBindings.xjb</bindingFile>
</bindingFiles>
</configuration>
并添加 paymentCheckBinding.xjb 如下
<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings
wsdlLocation="PaymentCheck.wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.1"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxws:bindings
node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='http://account.ws.integration.payment.te.com/PaymentCheckWS']">
<jaxb:bindings
node="//xs:simpleType[@name='subFailureType']/xs:restriction/xs:enumeration[@value='FA01']">
<jaxb:typesafeEnumMember name="FA01" />
</jaxb:bindings>
</jaxws:bindings>
</jaxws:bindings>
使用 wsimport 从 WSDL 生成 java 类 时枚举名称正在更改:
pom.xml
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.3</version>
<configuration>
<wsdlLocation>http://localhost/service/*</wsdlLocation>
<wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
<xdebug>true</xdebug>
<verbose>true</verbose>
<target>2.0</target>
<keep>true</keep>
</configuration>
<executions>
<execution>
<id>PaymentCheck</id>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<packageName>com.pay.jaxws.paymentCheck</packageName>
<wsdlDirectory>${basedir}/src/main/resources/wsdl/internal</wsdlDirectory>
<wsdlFiles>
<wsdlFile>PaymentCheck.wsdl</wsdlFile>
</wsdlFiles>
</configuration>
</execution>
</executions>
</plugin>
WSDL 枚举描述为:
<schema> ....
<simpleType name="subFailureType">
<restriction base="string">
<enumeration value="SUCCESS"/>
<enumeration value="FA01" /> <!-- Failure code for - Not enough cover -->
<enumeration value="FA01" /> <!-- Failure code for - All other cases -->
</restriction>
</simpleType>
</schema>
生成Class:
@XmlType(name = "subFailureType")
@XmlEnum
public enum SubFailureType {
SUCCESS("SUCCESS"),
@XmlEnumValue("FA01")
FA_01("FA01"),
@XmlEnumValue("FA02")
FA_02("FA02");
private final String value;
SubFailureType(String v) {
value = v;
}
public String value() {
return value;
}
public static SubFailureType fromValue(String v) {
for (SubFailureType c: SubFailureType.values()) {
if (c.value.equals(v)) {
return c;
}
}
throw new IllegalArgumentException(v);
}
}
代替枚举 FA01/FA02 附加下划线 "FA_01" 出现在名称中。
有什么办法可以纠正这个问题吗?它与 2012 年提出的问题 wsimport generating enum types incorrectly with extra underscore 类似,没有找到任何解决方法或解决方案。
可以使用绑定解决这个问题,在pom.xml中添加了绑定条目:
<configuration>
<packageName>com.pay.jaxws.paymentCheck</packageName>
<wsdlDirectory>${basedir}/src/main/resources/wsdl/internal</wsdlDirectory>
<wsdlFiles>
<wsdlFile>PaymentCheck.wsdl</wsdlFile>
</wsdlFiles>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/wsdl/internal/paymentCheckBindings.xjb</bindingFile>
</bindingFiles>
</configuration>
并添加 paymentCheckBinding.xjb 如下
<?xml version="1.0" encoding="UTF-8"?>
<jaxws:bindings
wsdlLocation="PaymentCheck.wsdl"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" version="2.1"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxws:bindings
node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='http://account.ws.integration.payment.te.com/PaymentCheckWS']">
<jaxb:bindings
node="//xs:simpleType[@name='subFailureType']/xs:restriction/xs:enumeration[@value='FA01']">
<jaxb:typesafeEnumMember name="FA01" />
</jaxb:bindings>
</jaxws:bindings>
</jaxws:bindings>