用JAXB编组活动对象? [英] Marshalling an active object with JAXB?
问题描述
我试图封送一个将Thread扩展为XML的类,代码如下:
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()
{
}
}
}
这会导致我遇到此错误: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.
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.
如果我正确地理解了这一点,那就是它扩展了Thread的事实会导致此问题,但是我还没有在网上看到解决方案.
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?
推荐答案
注意:我是 JAXB(JSR-222) 专家组.
Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB (JSR-222) expert group.
如果将MOXy用作JAXB提供程序,则可以直接使用TransitionXML
类.这是因为MOXy不会尝试为java
或javax
包(例如java.lang.Thread
)中的类创建元数据.
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
.
您可以从以下位置获取MOXy二进制文件:
You can obtain the MOXy binary from the following location:
要将MOXy指定为JAXB提供程序,您需要将一个名为jaxb.properties
的文件放在与域类相同的包中,并带有以下条目(请参阅:
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
这篇关于用JAXB编组活动对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!