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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Mysql Java type mapping

    MySQL Type Java Type ---------- --------- CHAR String VARCHAR String LONGVARCHAR String NUMERIC java ...

  8. JAXB - Annotations, Annotation for Classes: XmlType

    This annotation adds information that would be available from a schema type, but isn't implied by a ...

  9. 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 ...

随机推荐

  1. Android Studio工程导入另一个工程作为lib

    简单视频应用开发时,使用Vitamio作为视频解码库,官方建议直接以工程作为lib方便升级,将该工程导入到项目时不知道该怎么做,参考了下面的博客,这里存档标记一下. 参考:导入一个Android St ...

  2. 谈谈Nginx有哪些特点

    1.热部署        我个人觉得这个很不错.在master管理进程与worker工作进程的分离设计,使的Nginx具有热部署的功能,那么在7×24小时不间断服务的前提下,升级Nginx的可执行文件 ...

  3. leetcode@ [91] Decode Ways (Dynamic Programming)

    https://leetcode.com/problems/decode-ways/ A message containing letters from A-Z is being encoded to ...

  4. 安森美电量计采用内部电阻跟踪电流--电压HG-CVR

    http://www.dianyuan.com/article/34608.html LC709203F应用:用于便携式设备单节锂电池的智能电量计http://files.cnblogs.com/fi ...

  5. Objective-C Runtime 运行时之六:拾遗

    super 在Objective-C中,如果我们需要在类的方法中调用父类的方法时,通常都会用到super,如下所示: @interface MyViewController: UIViewContro ...

  6. STM32 SysTick定时器应用【worldsing笔记】

    SysTick是CM内核独立的定时器,时钟可以用内核内部的,也可以用芯片厂家(ST)的时钟,参考<Cortex-M3权威指南>的第13章: 另外也可以考<STM32F10xxx Co ...

  7. Oracle管道函数示例

    Oracle的管道函数需要定义下面的三样: Record/Object Type:定义一个Record或Object类型的变量,这个变量用于表示返回结果集的一行数据,有点像C#中的DataRow类. ...

  8. ecshop如何去除后台左侧云服务中心菜单

    介绍一下如何去除后台云服务中心菜单: 打开admin/templates/menu.htm,把539行的 document.getElementById("menu-ul").in ...

  9. RxJava的使用

    前言 RxJava及RxAndroid比较详细的介绍可以参考该文档<给 Android 开发者的 RxJava 详解> 基本介绍 ReactiveX 及 RxJava使用大部分来自和参考& ...

  10. TFS上使用Beyond Compare来比较源码

    In Visual Studio, go to the Tools menu, select Options, expand Source Control, (In a TFS environment ...