4
votes

I have a class which declares a Joda Time DateTime field.

However, the value of this isn't set by the unmarhsalling process, instead it's set later in the afterUnmarhsal method.

Therefore, the field is marked XmlTransient:

@XmlTransient
private DateTime startTime;

However, when trying to start up, I'm faced with this error:

javax.xml.bind.JAXBException: Exception Description: The class org.joda.time.DateTime$Property requires a zero argument constructor or a specified factory method. Note that non-static inner classes do not have zero argument constructors and are not supported. - with linked exception: [Exception [EclipseLink-50001] (Eclipse Persistence Services - 2.2.0.v20110202-r8913) ...

Why should JAXB care about this class, given that it's clearly transient for marhsalling & unmarshalling purposes?

How can I tell JAXB to ignore this field? I'm aware that I could put a factory method on there, but it seems pointless, given that the factory won't be able to instantiate the value (which is why it's done in afterUnmarshal)

1
This bug sounds familiar (I'll investigate). Have you tried a newer version, the current release is 2.3.2: eclipse.org/eclipselink/downloadsbdoughan
@BlaiseDoughan Thanks for the follow-up, and for the headsup on the latest version. Just tried with 2.3.2 (2.3.2.v20111125-r10461), and got the same error. FYI - The Maven Page of the wiki is out of date, and only lists releases up to 2.2.0 (which is how I missed it).Marty Pitt

1 Answers

1
votes

There appears to be a bug in EclipseLink 2.2.0 that has been fixed in later EclipseLink releases. You will still see this exception in the latest EclipseLink release if you use the default access (XmlAccessType.PUBLIC), but annotate the field:

package forum9610190;

import javax.xml.bind.annotation.XmlTransient;
import org.joda.time.DateTime;

public class Root {

    @XmlTransient
    private DateTime startTime;

    public DateTime getStartTime() {
        return startTime;
    }

    public void setStartTime(DateTime startTime) {
        this.startTime = startTime;
    }

}

Option #1 - Annotate the Property

Instead of annotation field, you can annotate the property (get method) with @XmlTransient:

package forum9610190;

import javax.xml.bind.annotation.XmlTransient;
import org.joda.time.DateTime;

public class Root {

    private DateTime startTime;

    @XmlTransient
    public DateTime getStartTime() {
        return startTime;
    }

    public void setStartTime(DateTime startTime) {
        this.startTime = startTime;
    }

}

Option #2 - Annotate the Field and use @XmlAccessorType(XmlAccessType.FIELD)

If you wish to annotate the field, then you will need to specify @XmlAccessorType(XmlAccessType.FIELD) on your class:

package forum9610190;

import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlTransient;
import org.joda.time.DateTime;

@XmlAccessorType(XmlAccessType.FIELD)
public class Root {

    @XmlTransient
    private DateTime startTime;

    public DateTime getStartTime() {
        return startTime;
    }

    public void setStartTime(DateTime startTime) {
        this.startTime = startTime;
    }

}

For More Information