小编Fil*_*lto的帖子

使用JAXB和JAXWS Annotations将枚举属性编组到XML中

假设我们有以下Java 1.5枚举:

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

@XmlAccessorType(XmlAccessType.FIELD)
public enum ReturnCode {
    OK(0,"Ok"),
    ERROR_VALIDATION(1,"Validation Error"),
    ERROR_TRANSPORT(2, "Transport Error"),
    ERROR_CASE_01(101, "Business situation #01"),
    ERROR_CASE_02(102, "Business situation #02"),
    ERROR_CASE_03(103, "Business situation #03");

    @XmlElement(nillable=false, required=true)
    private Integer code = 0;

    @XmlElement(nillable=false, required=true)
    private String message = null;

    private ReturnCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在使用Apache CXF和生成的WSDL,正如预期的那样,将上述枚举转换为限制:

<xsd:simpleType name="ReturnCode">
    <xsd:restriction base="xsd:string">
        <xsd:enumeration …
Run Code Online (Sandbox Code Playgroud)

enums web-services cxf jax-ws jaxb

7
推荐指数
1
解决办法
5625
查看次数

标签 统计

cxf ×1

enums ×1

jax-ws ×1

jaxb ×1

web-services ×1