JAXB - Annotations, Class Fields as Attributes: XmlAttribute
Provided that XML lets you represent a data item as a single value, there is no cut-and-dried rule for deciding between using an element or an attribute. (If you look for guidance, the schema describing the XML Schema language itself, making judicious use of both, is a good example.) JAXB, of course, has to be told when to make a field into an XML attribute.
The annotation for creating an XML attribute is XmlAttribute. Its elements correspond to what can be defined in an XML schema:
namedefines the namestring for the attribute, the default being the class field's name.namespacespecifies the XML target namespace to be used for the attribute's name.- A "true" value of
requiredis the same as using the XML Schema definition's attributeuse="required".
If you ask about some way for defining the equivalent for the XML Schema attribute default="value", then the simple answer is: "Do it yourself." Just write the getter so that it returns the default value if the field's value is null.
It's possible to annotate a static final field with XmlAttribute. This has the same effect as an XML Schema definition where the attribute element's attribute fixed is set to that value.
@XmlAttribute
final static int answer = 42;
JAXB - Annotations, Class Fields as Attributes: XmlAttribute的更多相关文章
- JAXB - Annotations, Controlling Element Selection: XmlAccessorType, XmlTransient
If JAXB binds a class to XML, then, by default, all public members will be bound, i.e., public gette ...
- JAXB - Annotations, The Annotation XmlElement
The basic annotation for a field that's intended to be an element is XmlElement. It permits you to d ...
- JAXB - Annotations, Annotation for Classes: XmlType
This annotation adds information that would be available from a schema type, but isn't implied by a ...
- JAXB - Annotations, The Object Factory: XmlRegistry, XmlElementDecl
To be able to create objects from XML elements, the unmarshaller must have an object factory with me ...
- JAXB - Annotations, Type Adapters: XmlJavaTypeAdapter
For some Java container types JAXB has no built-in mapping to an XML structure. Also, you may want t ...
- JAXB - Annotations, Top-level Elements: XmlRootElement
A class that describes an XML element that is to be a top-level element, i.e., one that can function ...
- 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 ...
- JAXB - Annotations, Type Mapping: XmlSchemaType
The annotation XmlSchemaType defines a mapping between an arbitrary Java type and a simple schema bu ...
- JAXB - Annotations, Annotations for Enums: XmlEnum, XmlEnumValue
An enum type is annotated with XmlEnum. It has an optional element value of type java.lang.Class whi ...
随机推荐
- Android Activity 生命周期中onStart()和onResume()的区别
首先了解Activity的四种状态 Running状态:一个新的Activity启动入栈后,它在屏幕最前端,处于栈的最顶端,此时它处于可见并可和用户交互的激活状态.Paused状态:当Activity ...
- matlab 函数说明--waitforbuttonpress
这个函数的名称取得不是太好,一眼看去,好像是等待按键的意思,但是实际上它等待的是按键或者鼠标事件,他的功能描述如下: 停止脚本的执行,直至当前活动的窗口上检测到了鼠标按下事件或者有效的键盘事件(有效是 ...
- Error starting static Resources java.lang.IllegalArgumentException: Document base D:\Program Files\apache-tomcat-xxx\webapps\xxx does not exist or is not a readable directory
网上的答案大多数如下: 但并没有解决我的问题 经过我的观察: 在tomcat的server.xml有Lottery项目描述,但实际上,该项目已被我删除,不存在于webapps中了 该行Cont ...
- 流(stream)
流的概念 Java程序通过流来完成输入/输出.流是生产或消费信息的抽象.流通过Java的输入/输出系统与物理设备链接.尽管与它们链接的物理设备不尽相同,所有流的行为具有同样的方式.这样,相同的输入/输 ...
- 10段实用的HTML5代码
1.HTML5编写的CSS ResetCSS Reset也可以写成Reset CSS,即重设浏览器样式. /* html5doctor.com Reset Stylesheet (Eric Mey ...
- A Tour of Go Switch evaluation order
Switch cases evaluate cases from top to bottom, stopping when a case succeeds. (For example, switch ...
- hdu 1597 find the nth digit
find the nth digit Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 针对 .NET 框架的安全编码指南
此主题尚未评级 - 评价此主题 发布日期 : 10/9/2004 | 更新日期 : 10/9/2004 Microsoft Corporation 适用于: Microsoft .NET 框架 摘 ...
- MapReduce的流程
1. Inputformat会从job的INPUT_DIR目录下读入待处理的文件,检查输入的有效性并将文件切分成InputSplit列表.Job实例可以通过setInputFormatClass(Cl ...
- vertical-align:top在单词和中文的表现
<ul> <li> <img src="../../saasdist_v2/images/staff-img.png" alt="" ...