June 22, 2011

EclipseLink 2.3 Release Available for Download

On behalf of the MOXy JAXB committers (great job by all), I am very proud to announce that EclipseLink 2.3 has been released and is available for download.  In this post I will summarize what is new in the MOXy component:
New Feature - Extensible Models

JAXB allows you to map fields/properties on your domain model to/from XML.  In MOXy we have introduced the concept of "virtual properties".  Virtual properties are configured through MOXy's external metadata and accessed via generic get/set methods.  Virtual properties have the same capabilities as the real properties in your model.  EclipseLink JPA also has support for virtual properties allowing you to build truly extensible applications (see EclipseLink MySports Example).

package blog.metadatasource.refresh;

import java.util.HashMap;
import java.util.Map;

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import org.eclipse.persistence.oxm.annotations.XmlVirtualAccessMethods;

@XmlType(propOrder={"firstName", "lastName", "address"})
public class Customer {

    private String name;
    private Address billingAddress;
    private Map<String, Object> extensions = new HashMap<String, Object>();

    public String getName() {
        return name;

    public void setName(String name) {
        this.name = name;

    public Address getBillingAddress() {
        return billingAddress;

    public void setBillingAddress(Address billingAddress) {
        this.billingAddress = billingAddress;

    public Object get(String key) {
        return extensions.get(key);

    public void set(String key, Object value) {
        extensions.put(key, value);


Detailed Examples:

    New Feature - External Metadata

    Developers can now store mappings using a MetadataSource external to the running application so that mapping overrides and extended mappings can be more dynamically integrated into deployed applications.

    package blog.metadatasource;
    import java.net.URL;
    import java.util.Map;
    import javax.xml.bind.JAXBContext;
    import javax.xml.bind.JAXBException;
    import org.eclipse.persistence.jaxb.metadata.MetadataSourceAdapter;
    import org.eclipse.persistence.jaxb.xmlmodel.XmlBindings;
    public class ExampleMetadataSource extends MetadataSourceAdapter {
        private JAXBContext xmlBindingsContext;
        public ExampleMetadataSource() throws JAXBException {
            xmlBindingsContext = JAXBContext.newInstance("org.eclipse.persistence.jaxb.xmlmodel");
        public XmlBindings getXmlBindings(Map<String, ?> properties, ClassLoader classLoader) {
            try {
                URL xmlBindings = classLoader.getResource("blog/metadatasource/binding.xml");
                return (XmlBindings) xmlBindingsContext.createUnmarshaller().unmarshal(xmlBindings);
            } catch(JAXBException e) {
                throw new RuntimeException(e);

    Detailed Examples:

    New Feature - Mapping Enhancements

    Map to Element Based on Attribute Value

    We have extended our @XmlPath extension to support predicates.  This gives you even more control over your object-to-XML mappings:

    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlRootElement;
    import org.eclipse.persistence.oxm.annotations.XmlPath;
    public class Customer {
        private Address billingAddress;
        private Address shippingAddress;

    Detailed Example

    Overriding JAXB's Java to XML Naming Algorithm

    JAXB provides a default algorithm for converting Java names to XML names.  You can override the default name through the use of annotations.  If you making many overrides based on the same naming rules this process can become tedious an error prone.  This is why we have introduced a mechanism that allows you to supply your own naming algorithm;
    package blog.namemangling;
    import org.eclipse.persistence.oxm.XMLNameTransformer;
    public class NameMangler implements XMLNameTransformer {
        public String transformRootElementName(String name) {
            return name.substring(name.lastIndexOf('.') + 1);
        public String transformTypeName(String name) {
            return transformRootElementName(name) + "Type";
        public String transformElementName(String name) {
            StringBuilder strBldr = new StringBuilder();
            for(char character : name.toCharArray()) {
                if(Character.isUpperCase(character)) {
                } else {
            return strBldr.toString();
        public String transformAttributeName(String name) {
            return name.toUpperCase();

    Detailed Example:

    Bugs & Enhancements

    Below is a link to all the bugs and enhancements that were fixed in the EclipseLink JAXB and SDO components in EclipseLink 2.3:

    What's Next?

    Work has already begun on the next release of EclipseLink JAXB (MOXy).  Stay tuned to this blog and over the next few weeks I'll be unveiling what we're doing next.  If there is a feature you would like to see please log an enhancement request and/or consider becoming a committer on the project.  In the meantime check out EclipseLink 2.3:

      No comments:

      Post a Comment

      Note: Only a member of this blog may post a comment.