简体   繁体   English

存在@XmlRootElement批注时,无法封送Java类

[英]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.

相关问题 JMS消息,由于缺少@XmlRootElement批注,因此无法将类型“ java.lang.String”作为元素封送 - JMS message, unable to marshal type “java.lang.String” as an element because it is missing an @XmlRootElement annotation 无法将类型“java.lang.Integer”编组为元素,因为它缺少 @XmlRootElement 注释 - unable to marshal type "java.lang.Integer" as an element because it is missing an @XmlRootElement annotation 无法将类型编组为XML元素,因为缺少@XmlRootElement注释 - Unable to marshal type as XML element because @XmlRootElement annotation is missing 无法将类型 [...] 编组为元素,因为它缺少 @XmlRootElement 注释 - unable to marshal type […] as an element because it is missing an @XmlRootElement annotation Java - XmlRootElement 注释 - Java - XmlRootElement annotation 无法将类型编组为元素,因为它缺少自动生成的类的 @XmlRootElement 注释 - unable to marshal type as an element because it is missing an @XmlRootElement annotation for auto generated classes 我有@xmlrootelement,但一直收到此异常:无法将类型编组为元素,因为它缺少@XmlRootElement - I have @xmlrootelement , but keep getting this exception: unable to marshal type as an element because it is missing an @XmlRootElement Marshal不是@XmlRootElement,JAXB为String - Marshal not @XmlRootElement with JAXB to String 了解JAXB @XmlRootElement批注 - Understanding JAXB @XmlRootElement annotation @XmlRootElement批注读入模型 - @XmlRootElement annotation to read into model
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM