Reputation: 2967
I am trying to annotate my java method as @XmlTransient
in my java class like below.
@XmlAccessorType(XmlAccessType.PROPERTY)
public abstract class MyClass {
@XmlTransient
public void addsomething{
// do something
}
}
When I try to use this class in my JaxBContext through other class I am getting following exception
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()
,
But when I see XmlTransient()
annotation definition(@Target(value={FIELD,METHOD,TYPE}))
it's clearly said be to work with methods. And In the JavaDoc(http://docs.oracle.com/javaee/7/api/javax/xml/bind/annotation/XmlTransient.html) it says
The @XmlTransient annotation can be used with the following program elements:
a JavaBean property
field
class
Can't I use @XmlTransient
on methods?
Upvotes: 2
Views: 4829
Reputation: 149017
The only methods that @XmlTransient
can be used are those that begin with get
or set
. These methods used in combination are used to expose a property in Java. @XmlTransient
can be placed on either the get
or set
method.
Get Method
The get method must take no parameters and return a value:
public String getFoo() {
return foo;
}
Set Method
The set method must take one parameter.
public void setFoo(String foo) {
this.foo = foo;
}
Upvotes: 5