java - CXF 不生成枚举映射?

标签 java web-services enums wsdl cxf

我正在使用 wsdl 文件中的 CXF (wsdl2java) 生成类,但是一个枚举只映射到 String

如果我打开生成的类,这是 wsdl 片段:

 <complexType>
    <complexContent>
      <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
        <attribute name="Type" use="required">
          <simpleType>
            <restriction base="{http://www.w3.org/2001/XMLSchema}string">
              <enumeration value="AAA"/>
              <enumeration value="VVV"/>
            </restriction>
          </simpleType>
        </attribute>
      </restriction>
    </complexContent>
  </complexType>

为什么结果是 String 而不是 Enum? 这是自动生成的结果:

private String type;

public String getType() {
    return type;
}

public void setType(String value) {
    this.type = value;
}

更新:自定义绑定(bind)文件:

<jaxb:bindings    
    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    jaxb:version="2.1">


         <jaxb:bindings>
                <jaxb:bindings node="//xs:attribute[@name='Type']/xs:simpleType">
                 <jaxb:typesafeEnumClass ref="TestEnum" />
        </jaxb:bindings>
    </jaxb:bindings>
</jaxb:bindings>

最佳答案

"... one enum is instead mapped to a String only."

"Why is the result a String, and not an Enum?"

当您的枚举值之一不是有效的 Java 标识符(例如:以数字开头)时,可能会发生这种情况 - JAXB(cxf 的 wsdl2java 委托(delegate)工作)事实上被迫使用 String 字段,否则生成的代码将无法编译。

推荐阅读:http://blog.bdoughan.com/2011/08/jaxb-and-enums.html

关于java - CXF 不生成枚举映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23540869/

相关文章:

java - 我正在尝试将其添加到 onStart 方法上

scala - 我可以使用@switch 和枚举吗?

wcf - 消息安全异常 : Security processor was unable to find a security header in the message

java - 使用 NTLM 身份验证使用 soap 服务

c# - 在类之间编写共享枚举的最佳实践是什么

java - 使用 lombok 创建枚举

java - 访问消息驱动 Bean 中的 servlet 类

java - 基本数组 - Java

java - MarkLogic-Java 搜索查询示例 'not' 运算符

java - 对 Jersey 休息服务的并发请求