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:

@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 @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.

@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());
}
}

JAXB - Annotations, Annotations for Enums: XmlEnum, XmlEnumValue的更多相关文章

  1. JAXB - Annotations, Annotations for the Schema: XmlSchema

    This annotation can only be used with a package. It defines parameters that are derived from the xsd ...

  2. Table of Contents - JAXB

    Getting Started Hello World Hello World with Namespace xjc - 将 XML Schema 编译成 Java 类 wsimport: 编译 WS ...

  3. How Do Annotations Work in Java?--转

    原文地址:https://dzone.com/articles/how-annotations-work-java Annotations have been a very important par ...

  4. ABAP CDS - Annotations 注解

    Syntax ... annotation[.annotation1[.annotation2]][:value]  ... Effect Annotation that can be specifi ...

  5. Domain Driven Design and Development In Practice--转载

    原文地址:http://www.infoq.com/articles/ddd-in-practice Background Domain Driven Design (DDD) is about ma ...

  6. Android 网络框架之Retrofit2使用详解及从源码中解析原理

    就目前来说Retrofit2使用的已相当的广泛,那么我们先来了解下两个问题: 1 . 什么是Retrofit? Retrofit是针对于Android/Java的.基于okHttp的.一种轻量级且安全 ...

  7. Java中的反射和注解

    前言 在Java中,反射机制和注解机制一直是一个很重要的概念,那么他们其中的原理是怎么样呢,我们不仅仅需要会使用,更要知其然而之所以然. 目录 反射机制 反射如何使用 注解定义 注解机制原理 注解如何 ...

  8. Thinking in Java——笔记(20)

    Annotations They provide information that you need to fully describe your program, but that cannot b ...

  9. 基于redis分布式锁实现“秒杀”

    转载:http://blog.5ibc.net/p/28883.html 最近在项目中遇到了类似“秒杀”的业务场景,在本篇博客中,我将用一个非常简单的demo,阐述实现所谓“秒杀”的基本思路. 业务场 ...

随机推荐

  1. 50道经典的JAVA编程题(41-45)

    50道经典的JAVA编程题(41-45),苦逼的程序猿,晚上睡不着了编程吧~今天坚持做10道题!发现编程能是我快乐...O(∩_∩)O哈哈~能平静我烦乱的心,剩下5道题留到考试完了再做吧!该睡觉了.. ...

  2. 【创建本地仓库】【for Centos】CentOS下创建本地repository

    [日期]2014年4月24日 [平台]Centos 6.5 [工具]httpd yum-utils createrepo [步骤] 1)安装httpd. yum install httpd 2)安装y ...

  3. hdu4435-charge-station(搜索+贪心)

    题意&题解: http://www.cnblogs.com/wuminye/p/3245546.html 说实话看了题解觉得很简单,但是比赛的时候真的是毫无头绪. 然而印象中做过一道类似的二进 ...

  4. intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

    ActivityA到ActivityBintent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);//ActivityB不加入后退栈android:noHisto ...

  5. BroadcastReceiver学习笔记

    1.在代码中注册与在AndroiManifest.xml注册的区别 (a)在代码中注册可以控制注册与注销的时间.比如在onCreate-onDestory, onStart-onStop, onRes ...

  6. Swift对面向对象提供了良好的支持,下面介绍几个其独有的特性。

    Swift对面向对象提供了良好的支持,下面介绍几个其独有的特性. 懒加载属性 Swift在语言层面上提供了类中懒加载属性的支持,使用lazy作为关键字: class Renderer { lazy v ...

  7. onethink 系统函数中 生成随机加密key

    <?php /** * 生成系统AUTH_KEY */ function build_auth_key(){ $chars = 'abcdefghijklmnopqrstuvwxyz012345 ...

  8. DOM 的选择器 API

    在刚开始的时候,我们只能用 getElementById,getElementsByClassName,getElementsByTagName 这几个 DOM 方法查找 DOM 树中的元素.后来,在 ...

  9. ECSHOP在线手册布局参考图--登录/注册页 user_passport.dwt

        A.会员登录框 1,设置方法 自带模块 2,代码相关 user_passport.dwt 中 <div class="usBox_1 f_l"> <div ...

  10. iOS开发-自动布局和自动旋转

    今天学习自动布局中的自动调整尺寸大小. 一.尺寸分类 尺寸分类是对设备宽高的一种大致分类. 有两种具体的尺寸分类用来表示真机:紧凑(Compact)和标准(Regular).还有第三种分类可以在设计工 ...