JAXB - Annotations, Annotations for Enums: XmlEnum, XmlEnumValue
2016-05-20 15:35
465 查看
An enum type is annotated with
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
XmlEnum. It has an optional element
valueof type
java.lang.Classwhich defines the class used for the values used in the XML representation. Usually, and by default, this is
java.lang.Stringbut other types, even numeric ones, are equally possible. For a straightforward enum type, this is sufficient:
@XmlEnum public 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
@XmlEnumValueannotation 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.
@XmlEnum public 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()); } }
相关文章推荐
- ./configure: error: SSL modules require the OpenSSL library.
- [Leetcode刷题总结系列][Dynamic Programming]63. Unique Paths II
- hdoj-3530-Subsequence
- CRM开发要点(四)
- 26.UIWindow
- runOnUiThread在子进程中更新主进程UI
- kxbdSuperMarquee.js滚动的神器-推荐
- EasyUI tree-grid 数回显问题实现探讨
- Qt之统一的UI界面格式基调,漂亮的UI界面
- 高并发集中访问造成连接MYSQL报Cannot assign requested address错误
- iOS学习之—— UICollectionView导致的崩溃问题
- Build path ->No action available/classpath .project 作用
- [疯狂Java]基础类库:StringBuilder/StringBuffer
- UItableview的一些总结
- iOS学习之—— UIGestureRecognizerState的简单了解
- iOS学习之——改变UITabBarController中当前显示的viewController
- Flex builder3 调试弹出窗口Flex builder cannot locate the required version of Flash Player解决办法
- UI
- Android Studio在连接手机时候,出现"Instant Run requires 'Tools..."不能安装软件的问题
- Java--获取request中所有参数的方法