[英]Unable to marshal Java class when @XmlRootElement annotation is present
I am writing a netbeans platform application using nebteans 8.1, Java 1.8 under CentOS6.4. 我正在CentOS6.4下使用nebteans 8.1,Java 1.8编写一个netbeans平台应用程序。
I have a Java class that looks like this (import classes omitted): 我有一个看起来像这样的Java类(省略了导入类):
@XmlAccessorType(value = XmlAccessType.FIELD)
@XmlRootElement(name = "module-task")
public class MyTask extends BaseClass {
// methods, members
}
When I try marshalling it using JAXBContext, I get an error message claiming it is missing an @XmlRootElement annotation (when clearly there is one from the previous code snippet). 当我尝试使用JAXBContext封送它时,收到一条错误消息,声称它缺少@XmlRootElement批注(显然,以前的代码段中有一个)。
Can anyone suggest why the @XmRootElement annotation is not being recognised? 谁能建议为什么@XmRootElement注释不被识别?
You're not implementing Serializable
. 您没有实现
Serializable
。 That is the cause, because transforming the state of your object to XML is basically just a different way of serializing it. 这就是原因,因为将对象的状态转换为XML基本上只是序列化它的另一种方式。
Add implements java.io.Serializable
and if you don't want to provide a serialVersionUUID
, also add a @SuppressWarnings("serial")
annotation on the class. 添加
implements java.io.Serializable
,如果您不想提供serialVersionUUID
,请在类上添加@SuppressWarnings("serial")
批注。
This should take care of it. 这应该照顾它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.