6

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.

1 Answer 1

6

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

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.