Use JAXB for XML data binding
Overview
Java Architecture for XML Binding (JAXB) is an XML-to-Java binding technology that maps Java classes with XML schemas using...
- xjc schema compiler
- schemagen schema generator
- Runtime framework that supports marshalling and unmarshalling of XML documents to and from Java objects.
An XML schema defines the data elements and structure of an XML document.
JAXB is the default data binding technology used by the JAX-WS tooling.
WAS v9 supports the JAXB 2.2 specification. JAX-WS 2.2 requires JAXB 2.2.
The xjc schema compiler tool enables us to start with an XML schema definition (XSD) and then create a set of JavaBeans that map to the elements and types defined in the XSD schema.
We can also start with a set of JavaBeans and use the schemagen schema generator tool to create the XML schema.
In addition to using the tools from the command-line, we can invoke these JAXB tools from within the Ant build environments using the task...
com.sun.tools.xjc.XJCTask (xjc schema compiler tool)
...and the task...
com.sun.tools.jxc.SchemaGenTask (schemagen schema generator tool)
To use, add com.ibm.jaxb.tools.jar and the com.ibm.jaxws.tools.jar files to the classpath.
The JAXB runtime API enables marshaling of JAXB objects to XML files and unmarshaling the XML document back to JAXB class instances. The JAXB binding package, javax.xml.bind, defines the abstract classes and interfaces used directly with content classes. In addition the package defines the marshal and unmarshal APIs.
We can optionally use JAXB binding customizations to override the default generated type mappings. We can customize JAXB bindings using inline annotations in the source schema, or using an external bindings customization file to pass our customizations to the JAXB binding compiler, xjc, to control the Java type mappings. Alternatively, we can add Java annotations to existing Java classes to pass to the schema generator, schemagen, to control the schema or XML type mappings. See the JAXB specification for information regarding binding customization options and Java annotations.
- Generate an XML schema from a Java class
- Generate Java classes from an XML schema
- Marshal and unmarshal XML documents
Subtopics
- Use JAXB schemagen tooling to generate an XML schema file from a Java class
- Use JAXB xjc tooling to generate JAXB classes from an XML schema file
- Use the JAXB runtime to marshal and unmarshal XML documents
- xjc command for JAXB applications
- schemagen command for JAXB applications
- Use JAXB schemagen tooling to generate an XML schema file from a Java class
- Use JAXB xjc tooling to generate JAXB classes from an XML schema file
- Use the JAXB runtime to marshal and unmarshal XML documents
- xjc command for JAXB applications
- schemagen command for JAXB applications
Related:
JAXB Development and assembly tools Web services specifications and APIs JAXB 2.2 Reference implementation