【发布时间】:2013-12-18 15:09:02
【问题描述】:
我正在尝试在我的 java 类中将我的 java 方法注释为 @XmlTransient,如下所示。
@XmlAccessorType(XmlAccessType.PROPERTY)
public abstract class MyClass {
@XmlTransient
public void addsomething{
// do something
}
}
当我尝试通过其他类在我的 JaxBContext 中使用这个类时,我得到以下异常
JAXB annotation is placed on a method that is not a JAXB property
this problem is related to the following location:
at @javax.xml.bind.annotation.XmlTransient()
,
但是当我看到XmlTransient() 注释定义(@Target(value={FIELD,METHOD,TYPE})) 时,很明显是要使用方法。在 JavaDoc(http://docs.oracle.com/javaee/7/api/javax/xml/bind/annotation/XmlTransient.html) 中它说
The @XmlTransient annotation can be used with the following program elements:
a JavaBean property
field
class
我不能在方法上使用@XmlTransient 吗?
【问题讨论】:
-
no :) 正如 Javadoc 所说,你不能这样做
-
为什么要将
XmlTransient添加到void方法中?