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 ...
随机推荐
- 【转载】shell中的特殊变量$
shell中的特殊变量:变量名含义$0shell或shell脚本的名字$*以一对双引号给出参数列表$@将各个参数分别加双引号返回$#参数的个数$_代表上一个命令的最后一个参数$$代表所在命令的PID$ ...
- 【原创】alias与export
最近在看lualua相关的,其中k中有os.getenv('kroot'),看到~/.bashrc理由kroot但是为什么拿不到,后来发现写成了alias了,应该是export的. alias rer ...
- 【Java基础】Java设计模式简介
什么是设计模式 设计模式(Design pattern)是一套被反复使用.被多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了可重用代码.让代码更容易被他人理解.保证代码可靠性.设计 ...
- Spark常用RDD操作总结
aggregate 函数原型:aggregate(zeroValue, seqOp, combOp) seqOp相当于Map combOp相当于Reduce zeroValue是seqOp每一个par ...
- CentOS 6.5 安装配置
关于CentOS的安装,网上有很多详细的教程.其实重点就在于硬盘的分区和软件的定制这两块.下面我在VirtualBox虚拟机上安装 CentOS-6.5-i386-minimal. 1.在起始菜单处选 ...
- HDU-4616 Game 树形DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4616 比较典型的树形DP题目,f[u][j][k]表示以点u为子树,经过 j 个陷阱的最大值,其中k= ...
- ./wls1036_linux32.bin: /lib/ld-linux.so.2: bad ELF interpreter
[CentOS]安装软件:/lib/ld-linux.so.2: bad ELF interpreter解决 环境: [orangle@localhost Downloads]$ uname -m ...
- Java TreeMap 源码解析
继上篇文章介绍完了HashMap,这篇文章开始介绍Map系列另一个比较重要的类TreeMap. 大家也许能感觉到,网络上介绍HashMap的文章比较多,但是介绍TreeMap反而不那么多,这里面是有原 ...
- 局域网Internet的共享
局域网接入Internet,之后,在服务器安装共享代理软件,可以使客户机通过代理软件接入Internet. 局域网接入Internet 而目前几乎所有的浏览器.下载软件.信件收发软件都支持代理服务器. ...
- sap 如何获取公司间采购订单或销售订单的交货状态
在上SAP项目过程,上了SD模块的企业一般都要做一些跟公司间采购订单或销售订单的交货状态的报表,通过这些报表可以经客户的业务上提供很大的灵活性,至于如何的灵活,还是那句老话“谁用谁知道".1 ...