Java Architecture for XML Binding
Encyclopedia
Java Architecture for XML Binding (JAXB) allows Java
developers to map Java classes
to XML
representations. JAXB provides two main features: the ability to marshal
Java objects
into XML and the inverse, i.e. to unmarshal XML back into Java objects. In other words, JAXB allows storing and retrieving data in memory in any XML format, without the need to implement a specific set of XML loading and saving routines for the program's class structure. It is similar to
.
JAXB is particularly useful when the specification is complex and changing. In such a case, regularly changing the XML Schema definitions to keep them synchronised with the Java definitions can be time consuming and error prone.
JAXB is a part of Java SE platform and one of the APIs
in the Java EE platform
, and is part of the Java Web Services Development Pack
(JWSDP). It is also one of the foundations for WSIT
. JAXB is part of SE version 1.6.
JAXB 1.0 was developed under the Java Community Process
as JSR 31. , JAXB 2.0 is being developed under JSR 222. Reference implementations for these specifications are available under the CDDL open source license at java.net.
, XML DTD
, and WSDL
are supported experimentally) to class representations. Classes are marked up using annotations
from javax.xml.bind.annotation.* namespace, for example, @XmlRootElement and @XmlElement. XML list sequences are represented by attributes of type java.util.List. Marshallers and Unmarshallers are created through an instance of JAXBContext.
In addition, JAXB includes a "schemagen" tool which can essentially perform the inverse of "xjc", creating an XML Schema from a set of annotated classes.
Java (programming language)
Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities...
developers to map Java classes
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...
to XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
representations. JAXB provides two main features: the ability to marshal
Serialization
In computer science, in the context of data storage and transmission, serialization is the process of converting a data structure or object state into a format that can be stored and "resurrected" later in the same or another computer environment...
Java objects
Object (computer science)
In computer science, an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure...
into XML and the inverse, i.e. to unmarshal XML back into Java objects. In other words, JAXB allows storing and retrieving data in memory in any XML format, without the need to implement a specific set of XML loading and saving routines for the program's class structure. It is similar to
xsd.exe
and XmlSerializer in the .NET Framework.NET Framework
The .NET Framework is a software framework that runs primarily on Microsoft Windows. It includes a large library and supports several programming languages which allows language interoperability...
.
JAXB is particularly useful when the specification is complex and changing. In such a case, regularly changing the XML Schema definitions to keep them synchronised with the Java definitions can be time consuming and error prone.
JAXB is a part of Java SE platform and one of the APIs
Application programming interface
An application programming interface is a source code based specification intended to be used as an interface by software components to communicate with each other...
in the Java EE platform
Java Platform, Enterprise Edition
Java Platform, Enterprise Edition or Java EE is widely used platform for server programming in the Java programming language. The Java platform differs from the Java Standard Edition Platform in that it adds libraries which provide functionality to deploy fault-tolerant, distributed, multi-tier...
, and is part of the Java Web Services Development Pack
Java Web Services Development Pack
The Java Web Services Development Pack is a free software development kit for developing Web Services, Web applications and Java applications with the newest technologies for Java....
(JWSDP). It is also one of the foundations for WSIT
Web Services Interoperability Technology
Web Services Interoperability Technology is an open-source project started by Sun Microsystems to develop the next-generation of Web service technologies...
. JAXB is part of SE version 1.6.
JAXB 1.0 was developed under the Java Community Process
Java Community Process
The Java Community Process or JCP, established in 1998, is a formalized process that allows interested parties to get involved in the definition of future versions and features of the Java platform....
as JSR 31. , JAXB 2.0 is being developed under JSR 222. Reference implementations for these specifications are available under the CDDL open source license at java.net.
Usage
The tool "xjc" can be used to convert XML Schema and other schema file types (as of Java 1.6, RELAX NGRELAX NG
In computing, RELAX NG is a schema language for XML, based on Murata Makoto's RELAX and James Clark's TREX. A RELAX NG schema specifies a pattern for the structure and content of an XML document...
, XML DTD
Document Type Definition
Document Type Definition is a set of markup declarations that define a document type for SGML-family markup languages...
, and WSDL
Web Services Description Language
The Web Services Description Language is an XML-based language that is used for describing the functionality offered by a Web service. A WSDL description of a web service provides a machine-readable description of how the service can be called, what parameters it expects and what data structures...
are supported experimentally) to class representations. Classes are marked up using annotations
Java annotation
An annotation, in the Java computer programming language, is a special form of syntactic metadata that can be added to Java source code. Classes, methods, variables, parameters and packages may be annotated...
from javax.xml.bind.annotation.* namespace, for example, @XmlRootElement and @XmlElement. XML list sequences are represented by attributes of type java.util.List. Marshallers and Unmarshallers are created through an instance of JAXBContext.
In addition, JAXB includes a "schemagen" tool which can essentially perform the inverse of "xjc", creating an XML Schema from a set of annotated classes.
Default data type bindings
The table below lists the mappings of XML Schema (XSD) data types to Java data types in JAXB.XML Schema Type | Java Data Type |
---|---|
xsd:string | java.lang.String |
xsd:positiveInteger | java.math.BigInteger |
xsd:int | int |
xsd:long | long |
xsd:short | short |
xsd:decimal | java.math.BigDecimal |
xsd:float | float |
xsd:double | double |
xsd:boolean | boolean |
xsd:byte | byte |
xsd:QName | javax.xml.namespace.QName |
xsd:dateTime | javax.xml.datatype.XMLGregorianCalendar |
xsd:base64Binary | byte[] |
xsd:hexBinary | byte[] |
xsd:unsignedInt | long |
xsd:unsignedShort | int |
xsd:unsignedByte | short |
xsd:unsignedLong | java.math.BigDecimal |
xsd:time | javax.xml.datatype.XMLGregorianCalendar |
xsd:date | javax.xml.datatype.XMLGregorianCalendar |
xsd:g | javax.xml.datatype.XMLGregorianCalendar |
xsd:anySimpleType (for xsd:element of this type) | java.lang.Object |
xsd:anySimpleType (for xsd:attribute of this type) | java.lang.String |
xsd:duration | javax.xml.datatype.Duration |
xsd:NOTATION | javax.xml.namespace.QName |
See also
- XML data bindingXML data bindingXML data binding refers to a means of representing information in an XML document as an object in computer memory. This allows applications to access the data in the XML from the object rather than using the DOM or SAX to retrieve the data from a direct representation of the XML itself.An XML data...
- JiBXJiBXJiBX is an open source Java framework for XML data binding. It solves the same problem as JAXB, XMLBeans and JDOM , but works differently. It lets developers work with data from XML documents using Plain Old Java Objects . The JiBX framework uses a binding definition to tell it how the Java...
– one of the fastest XML data binders - XMLBeansXMLBeansXMLBeans is a Java-to-XML binding framework which is part of the Apache Software Foundation XML project.-Description:XMLBeans is a tool that allows access to the full power of XML in a Java friendly way...
– a similar and complementary technology to JAXB from Apache Software FoundationApache Software FoundationThe Apache Software Foundation is a non-profit corporation to support Apache software projects, including the Apache HTTP Server. The ASF was formed from the Apache Group and incorporated in Delaware, U.S., in June 1999.The Apache Software Foundation is a decentralized community of developers... - TopLinkTopLinkIn computing, TopLink is an object-relational mapping package for Java developers. It provides a framework for storing Java objects in a relational database or for converting Java objects to XML documents....
– an object to relational and object to XMLXMLExtensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....
mapper from OracleOracle CorporationOracle Corporation is an American multinational computer technology corporation that specializes in developing and marketing hardware systems and enterprise software products – particularly database management systems...
that supports JAXB 1.0 - EclipseLinkEclipseLinkEclipseLink is the open source Eclipse Persistence Services Project from the Eclipse Foundation. The software provides an extensible framework that allows Java developers to interact with various data services, including databases, web services, Object XML mapping , and Enterprise Information Systems...
MOXy – Open SourceOpen sourceThe term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...
implementation of JAXB and object XML mapping services under the Eclipse FoundationEclipse FoundationThe Eclipse Foundation is a not-for-profit, member supported corporation that hosts the open-source Eclipse Projects and helps cultivate both an open source community and an ecosystem of complementary products and services...
External links
- JAXB home page Reference Implementation on Project GlassFishGlassFishGlassFish is an open source application server project started by Sun Microsystems for the Java EE platform and now sponsored by Oracle Corporation. The supported version is called Oracle GlassFish Server...
- previous JAXB home page
- A JAXB Tutorial by Wolfgang Laun
- JSR 222 (JAXB 2.0)
- JSR 31 (JAXB 1.0)
- JAXB chapter of the Java EE 5 Tutorial
- JAXB Wizard