【问题标题】:Marshalling an active object with JAXB?使用 JAXB 编组活动对象?
【发布时间】:2012-11-05 21:15:49
【问题描述】:

我正在尝试编组一个将 Thread 扩展为 XML 的类,代码如下:

@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.

如果我理解正确的话,它扩展 Thread 的事实会导致这个问题,但我还没有在网上看到解决方案。

除了使类成为实现可运行的对象之外,有没有人知道解决方案或解决方法?

【问题讨论】:

    标签: java jaxb marshalling active-objects


    【解决方案1】:

    注意:我是EclipseLink JAXB (MOXy) 的负责人,也是JAXB (JSR-222) 专家组的成员。

    如果您使用 MOXy 作为您的 JAXB 提供程序,那么您可以按原样使用您的 TransitionXML 类。这是因为 MOXy 不会尝试为 javajavax 包(例如 java.lang.Thread)中的类创建元数据。

    您可以从以下位置获取 MOXy 二进制文件:

    要将 MOXy 指定为您的 JAXB 提供程序,您需要将名为 jaxb.properties 的文件与您的域类放在同一个包中,并使用以下条目(请参阅:http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html)。

    javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory
    

    【讨论】:

    • 我忘了说我用的是Netbeans,有没有办法给它添加Moxy,也许是一个插件?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多