JAXB - Annotations, Annotation for Classes: XmlType

Posted huey

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAXB - Annotations, Annotation for Classes: XmlType相关的知识,希望对你有一定的参考价值。

This annotation adds information that would be available from a schema type, but isn‘t implied by a Java class declaration. The annotation has several attributes:

  • factoryClass and factoryMethod define the class containing a no-argument method for creating an instance of this class as the equivalent of an empty XML element.
  • The attribute name provides the XML schema name if you don‘t want to use the class name.
  • The namespace attribute provides the name of the target namespace.
  • The string array value defined by propOrder establishes an ordering of the sub-elements. (It‘s pretty obvious that there can‘t be a connection between the textual order of items in a class definition and the order its fields are returned by reflection methods.)

Here is an example for XmlType, requesting that the elements titleitems and cluster should appear in the given order:

@XmlRootElement
@XmlType( propOrder={ "title", "items", "cluster" } )
public class Document {
    ...
}

 

以上是关于JAXB - Annotations, Annotation for Classes: XmlType的主要内容,如果未能解决你的问题,请参考以下文章

JAXB - Annotations, Top-level Elements: XmlRootElement

java JAXB注解

JAXB实现java对象与xml之间转换

XML编程总结——使用JAXB进行java对象和xml格式之间的相互转换

java操作xml超简单的方法

向枚举添加值时的 Semver