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.

最新文章

  1. unity, reduce android size
  2. C++ 多态的实现原理与内存模型
  3. SAPScript、Smartforms动态打印图像或者背景图片
  4. 1891: 丘比特的烦恼 - BZOJ
  5. Hibernate查询效率对比
  6. Spring MVC中DispatcherServlet工作原理探究
  7. ZOJ Goldbach 2013年长沙赛区网络赛
  8. delphi中无类型文件读写
  9. opencv----(1) mat最好用,和IplImage,cvmat 比较
  10. JS事件处理程序
  11. Visual Studio 2017 发布 15.5 版本,百度网盘离线安装包下载。
  12. paramiko向服务器自动上传下载文件
  13. PhpStorm 2017破解
  14. SVG的用法
  15. XML部分
  16. BAT大厂面试流程剖析
  17. text2
  18. linux上安装rabbitMQ
  19. 解决Linux中文显示乱码的问题
  20. ref:Mysql授权远程登陆

热门文章

  1. jquery 资料收集
  2. ffmpeg编码YUV420视频序列
  3. Java之Property-统获取一个应用程序运行的次数
  4. SQL2008--SQL语句-存储过程-触发器-事务处理-基本语法-函数
  5. mssql函数demo
  6. OWIN学习
  7. oracle强制使用索引
  8. CentOS6.5安装telnet
  9. 拼接json示例 json分页并显示所有页码
  10. java--静态的应用(工具类)