Reputation: 3446
In my JAXB classes, do I put the @XmlElement annotation above the private variable declaration?
@XmlElement(name = "report_name")
private String name;
Above the setter?
@XmlElement(name = "report_name")
public void setName(String name) {
this.name = name;
}
Or above the getter?
@XmlElement(name = "report_name")
public String getName() {
return name;
}
I've read through several JAXB tutorials and have yet to find a consistent pattern.
Upvotes: 6
Views: 3577
Reputation: 149007
By default JAXB impls treat public fields and properties as mapped. You can put the annotation on the get or set method and it will be treated the same. If you want to annotate the field you should specify @XmlAccessorType(XAccessType.FIELD)
on the class.
For More Information
Upvotes: 6