Question

I am trying to marshal a class which extends Thread to XML, the code is as follows:

@XmlRootElement
public class TransitionXML extends Thread {

ArcXML[] preArcs;
ArcXML[] postArcs;
int[] preArcTokens;
int[] postArcTokens;
int leastTime;
int longestTime;
String name;

//some methods 

//a lot of get-set

@Override
public void run() {
    while (true) {
        if (this.postTransition() & this.preTransition()) {
            //We take out the tokens.
            this.executePreTranstion();
            this.checkPreTransition();


            try {
                this.sleep(1000 * this.getTimeToPass());
            } catch (InterruptedException ex) {
                Logger.getLogger(TransitionXML.class.getName()).log(Level.SEVERE, null, ex);
            }

            //We see if we can put them in.
            if (this.postTransition()) {
                this.executePostTranstion();
                this.checkPostTransition();
            }

        } else {
            try {
                this.sleep(2000);
            } catch (InterruptedException ex) {
                Logger.getLogger(TransitionXML.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}


}

public TransitionXML()
{

}

}

}

Which leads me to this error: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 2 counts of IllegalAnnotationExceptions java.lang.Thread$UncaughtExceptionHandler is an interface, and JAXB can't handle interfaces. ... java.lang.Thread$UncaughtExceptionHandler does not have a no-arg default constructor.

If I understood this correctly the very fact that it extends Thread causes this problem but I haven't seen a solution on the net.

Does anyone know of a solution or work-around for this, besides making the class a object which implements runnable?

Was it helpful?

Solution

Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.

If you use MOXy as your JAXB provider then you can use your TransitionXML class as is. This is because MOXy will not attempt to create metadata for classes in a java or javax package such as java.lang.Thread.

You can obtain the MOXy binary from the following location:

To specify MOXy as your JAXB provider you need to put a file called jaxb.properties in the same package as your domain classes with the following entry (see: http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html).

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top