Default XML Element
I have the following class:
private String larquivoid;
private String oper;
private String type;
public String getType() {
return type;
}
public void setType(String type) {
this.type = Settings.NUMERIC_FIELD_VALUE;
}
@XmlValue
public String getLarquivoid() {
return larquivoid;
}
public void setLarquivoid(String larquivoid) {
this.larquivoid = larquivoid;
}
@XmlAttribute
public String getOper() {
return oper;
}
public void setOper(String oper) {
this.oper = oper;
}
type is an attribute that I don't want to use in my xml request. This gives the usual problem: if a class has a @XmlElement property, it cannot have a @XmlValue property.
How can I make my type only an attribute of this class?
source to share
What's going wrong?
By default, the unmapped property is treated as if it were being annotated with @XmlElement
. This is why you see the error you see.
How do I fix it?
Exclude less than half of the properties
If you need to exclude less than half of the class properties, you can annotate them individually with @XmlTransient
.
Exclude more than half of the properties
If you need to exclude more than half of the properties, I suggest annotating your class with @XmlAccessorType(XmlAccessType.NONE)
. This will cause only annotated properties to be treated as displayable.
source to share