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. 浏览器中显示视频,flash等的代码处理

    window.flashView=function(flash_url){ var html=''; html+='<div id="obj_flash_div">'; ...

  2. Ubuntu下部署SVN+SVNManager

    本文参考了一下博客,特此感谢: 灰烬之灵    一米阳光做IT.测试 环境描述:ubuntu 13.04 1.先创建svn组和svn用户: sudo addgroup svnsudo useradd ...

  3. Ubuntu 14.04.3 LTS 配置 DNS Server

    我们目的是用一台局域网机器完成 192.168.1.113 <-->cloudshield.com的解析,指定A记录和CNAME; 0.关于Ubuntu 14.04.2 LTS 下载.安装 ...

  4. 转载ASP.NET MVC 和ASP.NET Web Form简单区别

    转载原地址 http://www.cnblogs.com/lei2007/p/3315431.html 概论: Asp.net  微软 提供web开发框架或者技术.分Web Form和ASP.NET  ...

  5. CC_CALLBACK原理及应用

    http://my.oschina.net/u/555701/blog/219844 c++ 11 基础 :     std::function 类模版 std::function是一种通用.多态的函 ...

  6. 正确导入svn拉取的工程

    为什么要写这篇博文?主要是记录摸着石头过黄河的过程.之前在eclipse装了svn插件,拉取远程工程,在eclipse显示的工程,并不会分开显示模块工程,反而 是以总工程的姿态呈现.或许你觉得不管分模 ...

  7. centos vwwareTools 拷贝文件设置

    1. 在root 用户下面 在虚拟机菜单上面选择  Vwware Tools   虚拟机会将 安装文件  拷贝到桌面上面 拷贝这个文件 到 root 文件夹 /home/root 将XXX.tar.g ...

  8. WinForm程序启动控制台窗口Console

    本文转载:http://blog.csdn.net/oyi319/article/details/5753311 2.WinForm程序和控制台窗口Console 如果你调试过SharpDevelop ...

  9. php throw new Excpetion()之后,程序还往下继续运行吗?

    经过测试是不会往下执行的,直接catch抛出异常了.

  10. Java算法实例集合(2)

    这是Standford一位计算机老师的私藏,里面包含了不少Java/C++的算法实现代码.有兴趣的朋友可以看看.