博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JAXB - Annotations, Annotations for Enums: XmlEnum, XmlEnumValue
阅读量:4643 次
发布时间:2019-06-09

本文共 1702 字,大约阅读时间需要 5 分钟。

An enum type is annotated with XmlEnum. It has an optional element value of type java.lang.Class which defines the class used for the values used in the XML representation. Usually, and by default, this is java.lang.String but other types, even numeric ones, are equally possible. For a straightforward enum type, this is sufficient:

@XmlEnumpublic enum SubElemType {   //...(enum definition)}

Individual enum constants have to be annotated if there is a difference between the Java name and the string used to represent the value in XML. This is defined with an @XmlEnumValue annotation that is attached to individual enum constants. Its required element defines the XML representation string. If it might be useful for the Java application to have support for the conversion between Java values and XML representations as well, the enum type might define the XML representation as a parameter for the constructor, provide a getter for the XML string and perhaps even a lookup function (fromValue) to convert a string to the enum constant. Such a deluxe version of an enum type is shown below.

@XmlEnumpublic enum SubElemType {    @XmlEnumValue("PrMaSig")    PR_MA_SIG("PrMaSig"),    @XmlEnumValue("Track1")    TRACK_1("Track1"),    // ...(more enum constant definitions)    private final String value;    SubElemType(String v) {        value = v;    }    public String value() {        return value;    }    public static SubElemType fromValue(String v) {        for (SubElemType c: SubElemType.values()) {            if (c.value.equals(v)) {                return c;            }        }        throw new IllegalArgumentException(v.toString());    }}

 

转载于:https://www.cnblogs.com/huey/p/5512295.html

你可能感兴趣的文章
4.express 框架
查看>>
Java基础算法集50题
查看>>
Android 桌面组件widget
查看>>
25-字符串
查看>>
萌新报道
查看>>
Asp.Net 获取物理路径
查看>>
Apache2.4使用require指令进行访问控制--允许或限制IP访问/通过User-Agent禁止不友好网络爬虫...
查看>>
Solr reRankQuery加自定义函数实现搜索二次排序
查看>>
基于ipv6的抓包实验
查看>>
latex学习(四)tlmgr
查看>>
centos6.5 bugzilla4.4.5 汉化
查看>>
ros topic 发布一次可能会接收不到数据
查看>>
字符串的扩展
查看>>
冒泡排序_c++
查看>>
linux常见术语示意
查看>>
CodeForces743E. Vladik and cards 二分+状压dp
查看>>
GO语言面向对象
查看>>
1111评论
查看>>
CodeForces 546E - Soldier and Traveling(最大流)
查看>>
linux下(Window当然也可以)解决idea创建maven项目导入过慢问题
查看>>