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. HW6.13

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  2. 新手学习 Vim 的五个技巧

    多年来,我一直想学 Vim.如今 Vim 是我最喜欢的 Linux 文本编辑器,也是开发者和系统管理者最喜爱的开源工具.我说的学习,指的是真正意义上的学习.想要精通确实很难,所以我只想要达到熟练的水平 ...

  3. delphi 删除目录和创建目录,临时文件夹

    获取用户当前的Windows临时文件夹function GetWinTempPath: string;varTempDir: array[0..255] of char;beginGetTempPat ...

  4. 在多线程中进行UI操作

    那么在子线程中的UI操作如何处理呢?有两种方法: 一:在子线程,你需要进行的UI操作前添加dispatch_async函数,即可将代码块中的工作转回到主线程 dispatch_async(dispat ...

  5. ltt.js

    var dailyBox = $('.daily-box-office'), curDate = new Date(), curYear = curDate.getFullYear(), curMon ...

  6. 关于local storage 和 session storage以及cookie 区别简析

    session storage 和local storage 都是存储在客户端的浏览器内: 一:关于COOKIE 的缺陷 * Cookie的问题 * 数据存储都是以明文(未加密)方式进行存储 * 安全 ...

  7. 一、FreeMarker 模版开发指南 第一章 入门

    所有资料来自 南磊 翻译的官方文档,我弄简单了,适合自己以后拿出来翻看. 章节内容如下: 简介 模板+数据模型=输出 数据模型一览 模板一览 一.模板  +  数据模型  =  输出 输出结果: &l ...

  8. Android大图片裁剪终极解决方案 原理分析

    约几个月前,我正为公司的APP在Android手机上实现拍照截图而烦恼不已. 上网搜索,确实有不少的例子,大多都是抄来抄去,而且水平多半处于demo的样子,可以用来讲解知识点,但是一碰到实际项目,就漏 ...

  9. 时间紧迫,写一些 NavigationController 一次性返回2级界面甚至更多级的界面

    在NavigationController中,调用pushViewController可以将界面推到指定的界面,调用popToViewController可以返回上层界面,可是它的实现原理是什么? 好 ...

  10. 安装builderRobot到Rational Functional Tester和Performance Tester

    最近研究安装builder,稍微总结一下,以后继续补充: 1. Robot采用专业的测试脚本语言, 从而导致需要学习专门的API以及专门的语法外, 用进程化的Visual Basic作为脚本语言, 导 ...