JAXB - Annotations, Type Mapping: XmlSchemaType
The annotation XmlSchemaType
defines a mapping between an arbitrary Java type and a simple schema built-in type. Most of the time the default mapping is satisfactory, but every now and then an alternative may be more convenient. Let's assume that the processing of chunks of text requires their extension, either after unmarshalling or before the emitting marshalling. For this, a StringBuffer
is better than String
, which is the default mapping for xs:string
. Below are the essential Java classes, one defining TextType
as a container for a string, and the type adapter class for the simple conversion between String
and StringBuffer
. Notice that the latter class is specified in a separate annotation, i.e.,XmlJavaTypeAdapter
.
- public class TextType {
- @XmlElement
- @XmlSchemaType(name="string")
- @XmlJavaTypeAdapter( String2StrBuf.class )
- public StringBuffer strbuf;
- }
- public class String2StrBuf
- extends XmlAdapter<String,StringBuffer> {
- @Override
- public String marshal( StringBuffer strbuf ){
- return strbuf.toString();
- }
- @Override
- public StringBuffer unmarshal( String string ){
- return new StringBuffer( string );
- }
- }
Within the Java code that unmarshals or marshals an instance document, TextType
elements are now StringBuffers
, e.g.:
- TextType text = new TextType();
- text.strbuf = new StringBuffer( "This is the house" );
- // ...
- text.strbuf.append( " that Jack built." );
Such a type mapping can be defined either for an individual element or for all occurrences within a package. If you need multiple mappings at package level, you'll have to bundle theXmlSchemaType
annotations in an XmlSchemaTypes
(note the plural) annotation, and the XmlJavaTypeAdapter
annotiations are packed into a single XmlJavaTypeAdapters
annotation.
JAXB - Annotations, Type Mapping: XmlSchemaType的更多相关文章
- 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 ...
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-007UserTypes的用法(@org.hibernate.annotations.Type、@org.hibernate.annotations.TypeDefs、CompositeUserType、DynamicParameterizedType、、、)
一.结构 二.Hibernate支持的UserTypes接口 UserType —You can transform values by interacting with the plain JD ...
- JavaPersistenceWithHibernate第二版笔记-第五章-Mapping value types-005控制类型映射(Nationalized、@LOB、@org.hibernate.annotations.Type)
一.简介 1. 2. 3. 4. to override this default mapping. The JPA specification has a convenient shortcut a ...
- 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, 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 ...
- Mysql Java type mapping
MySQL Type Java Type ---------- --------- CHAR String VARCHAR String LONGVARCHAR String NUMERIC java ...
- 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, Annotations for the Schema: XmlSchema
This annotation can only be used with a package. It defines parameters that are derived from the xsd ...
随机推荐
- 把公共cpp包含到cocos2d-x内部编译的方法。。
找到cocos2d-x-3.0alpha0-pre\extensions\Android.mk文件,把自定义的cpp文件加进去即可..如果是其它系统就进相应的目录,找到配置文件添加即可..
- kvm guest usb mapping
http://www.linux-kvm.org/page/USB#Input_devices http://www.linux-kvm.org/page/USB_Host_Device_Assign ...
- MapReduce 开发环境搭建(Eclipse\MyEclipse + Maven)
写在前面的话 可详细参考,一定得去看 HBase 开发环境搭建(Eclipse\MyEclipse + Maven) Zookeeper项目开发环境搭建(Eclipse\MyEclipse + Mav ...
- CSS layout入门
元素与盒 在HTML中常常使用的概念是元素,而在CSS中,布局的基本单位是盒,盒总是矩形的. 元素与盒并非一一对应的关系,一个元素可能生成多个盒,CSS规则中的伪元素也可能生成盒,display属性为 ...
- jquery.validate.js 应用示例
今天发现了jQuery一个很强大的验证表单插件(jquery.validate.js 下载地址:http://bassistance.de/jquery-plugins/jquery-plugin-v ...
- 委托学习续:Action、Func和Predicate
我们先看一个上一章的委托的例子: using System; using System.Collections.Generic; using System.Linq; using System.Tex ...
- Java条件语句 switch case
不得不说的几点小秘密: 1. switch 后面小括号中表达式的值必须是整型或字符型 2. case 后面的值可以是常量数值,如 1.2:也可以是一个常量表达式,如 2+2 :但不能是变量或带有变量的 ...
- [转] C++ Redistributable Package版本详解
我们使用的程序常常都需要C++ Redistributable Package的支持.C++ Redistributable Package有众多版本,给安装带了不便. 目前(2013-12-04) ...
- CF 319B Psychos in a Line 【单调队列】
维护一个单调下降的队列. 对于每一个人,只需要找到在他前面且离他最近的可以杀掉他的人即可. #include <cstdio> #include <vector> #inclu ...
- IOS设置button 图片 文字 上下、左右
[btn setImage:imgNor forState:UIControlStateNormal]; [btn setImage:imgSel forState:UIControlStateSel ...