Reputation: 81
In Java , I add @XmlRootElement(name = "MyClass")
to my class , it let all properties in the class become xml elements , now I have one property ,it doesn't need to be xml element , what can I do ? Thank you. George
@XmlRootElement(name = "MyClass")
public class MyClass{
public String A ;
public String B ;
//what xml anotation to be set here ?
public String notXmlelement ;
}
Upvotes: 3
Views: 381
Reputation: 149047
If you are excluding less than half of the mapped fields/properties then you can do this using @XmlTransient
.
public Class {
public String a; // include
public String b; // include
public String c; // include
@XmlTransient public String d; // exclude
}
If you are excluding more than half of the mapped fields/properties then you can specify @XmlAccessorType(XmlAccessType.NONE)
and then only annotated fields/properties will be included.
@XmlAccessorType(XmlAccessType.NONE)
public Class {
public String a; // exclude
public String b; // exclude
public String c; // exclude
@XmlElement public String d; // include
}
Upvotes: 3
Reputation: 23627
If you have a field which should not be persisted as XML (I assume you are using JAXB), then mark it as @XmlTransient
.
@XmlTransient
public String notXmlelement;
Upvotes: 2