Jump to: navigation, search

EclipseLink/Release/2.4.0/JAXB RI Extensions/ID Resolver

Design Documentation: IDResolver

ER 360249





  • Deliver an abstract IDResolver class in the EclipseLink library that will provide the same functionality as the Sun extension.
    • Given a String id and Object obj, allow the user to perform custom bind code
    • Given a String id and Class type, allow the user to perform custom resolve code
    • Provide the user a hook into startDocument() and endDocument() events
  • Unlike Sun's JAXB implementation, EclipseLink MOXy is not restricted to String-only IDs. Therefore, we will add additional methods to support complex IDs.
    • Given a IDWrapper id and Object obj, allow the user to perform custom bind code
    • Given a IDWrapper id and Class type, allow the user to perform custom resolve





The user must extend the following abstract class:

package org.eclipse.persistence.jaxb;
import java.util.concurrent.Callable;
import javax.xml.bind.ValidationEventHandler;
import org.xml.sax.SAXException;
public abstract class IDResolver {
    public abstract Callable<?> resolve(String id, Class type) throws SAXException;
    public abstract void bind(String id, Object obj) throws SAXException;
    public void startDocument(ValidationEventHandler eventHandler) throws SAXException {
    public void endDocument() throws SAXException {

OPEN ISSUE: Should we include additional support for non-String, and composite keys? If so, should we include additional bind()/resolve() methods, or force the user to change to a new method signature?

The user's IDResolver class can then be passed to the EclipseLink Unmarshaller through the addProperty() method:

JAXBContext ctx = ...
Unmarshaller u = ctx.createUnmarshaller();
u.setProperty(IDResolver.class.getName(), new MyIDResolver());

XML Bindings




Appendix A - Example IDResolver

From Pluggable ID/IDREF handling in JAXB 2.0

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
import com.sun.xml.bind.IDResolver;
class MyIDResolver extends IDResolver {
    void startDocument() {
    public void bind(String id, Object obj) {
        if (obj instanceof Apple)
            apples.put(id, (Apple) obj);
            oranges.put(id, (Orange) obj);
        return new Callable() {
            public Object call() {
                if (targetType == Apple.class)
                    return apples.get(id);
                    return oranges.get(id);

Document History

Date Author Version Description & Notes
111007 Rick Barkhouse 1.00 : First draft
111017 Rick Barkhouse 1.01 : Considering possibility of supporting complex IDs
111020 Rick Barkhouse 1.02 : Revising design to support complex (non-String, composite) IDs