JAXB - The JAXB Context

Posted huey

tags:

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

As we have seen, an object of the class JAXBContext must be constructed as a starting point for other operations. One way is to create a context from a colon separated list of packages.

JAXBContext ctxt = JAXBContext.newInstance( "some foo:more.bar" );

Each package must contain its own class ObjectFactory or a file named jaxb.index. An ObjectFactory class is generated by the XML schema compiler, and therefore this form of newInstance is usually used in connection with schema derived classes. For JAXB annotated Java code, you may use the package path form as well, either with a hand-written ObjectFactory class or with a jaxb.index resource file containing a list of the class names to be considered by JAXB. This file simply lists the class names relative to the package where it occurs, e.g.:

# package some.foo
# class some.foo.Foo
Foo
# inner class some.foo.Foo.Boo
Foo.Boo

An alternative form of the newInstance method lists all classes that the new context should recognize.

JAXBContext ctxt = JAXBContext.newInstance( Foo.class, Bar.class );

Usually, the top level classes are sufficient since JAXB will follow, recursively, all static references, such as the types of instance variables. Subclasses, however, are not included.

If packages or classes are associated with namespaces, the packages or classes associated with a JAXB context also determine the namespace declarations written as attributes into the top-level element of the generated XML document.

 

以上是关于JAXB - The JAXB Context的主要内容,如果未能解决你的问题,请参考以下文章

JAXB 和编组

java.lang.LinkageError: JAXB 2.0 API is being loaded from the bootstrap classloader

如何克隆JAXB对象

将@Generated注释添加到JAXB生成的类中

Jaxb 2.0 Schema 验证问题

如何获取JAXB对象的命名空间