{{tip||XML names found in the metadata (complex type names, element names, attribute names) will be translated to Java identifiers according to the algorithms described in "Appendix D: Binding XML Names to Java Identifiers" of the [http://jcp.org/en/jsr/detail?id=222 Java Architecture for XML Binding (JAXB) 2.2 Specification]. In the example above, "last-name" in XML was translated to "lastName" for the Java object.}}

+

{{tip||XML names found in the metadata (complex type names, element names, attribute names) will be translated to Java identifiers according to the algorithms described in "Appendix D: Binding XML Names to Java Identifiers" of the [http://jcp.org/en/jsr/detail?id=222]. In the example above, "last-name" in XML was translated to "lastName" for the Java object.}}

Contents

Static and Dynamic Entities

There are two high-level ways to use EclipseLink JAXB; Using pre-existing Java classes (Static MOXy), or using EclipseLink-generated in-memory Java classes (Dynamic MOXy).

Using Static MOXy

The most common way to use EclipseLink JAXB is with existing Java classes, mapped to XML using Java annotations and/or EclipseLink OXM metadata. These classes might be ones that you have written yourself, or they could be generated from an XML Schema using the XJC compiler tool.

Using this approach, you will be dealing with your actual domain objects when converting to and from XML. The following example shows a simple Java class that can be used with JAXB:

When using static classes with JAXB, you can take advantage of JAXB's defaulting behaviour and only annotate things which differ from the default. For example, all fields on a Java class will default to being mapped to an XML element, so no annotation is needed on the 'name' field. We want the 'id' field, however, to map to an XML attribute, so have annotated it as such.

The code below demonstrates how to unmarshal, modify, and marshal object using static JAXB:

Using Dynamic MOXy

With EclipseLink Dynamic MOXy, you can bootstrap a JAXBContext from a variety of metadata sources and use existing JAXB APIs to marshal and unmarshal data… without having compiled Java class files on the classpath. This allows you to alter the metadata as needed, without having to update and recompile the previously-generated Java source code.