Where in my class do I put @XmlElement Annotation?

In my JAXB classes, do I put an @XmlElement annotation over a private variable declaration?

@XmlElement(name = "report_name") private String name; 

Above the installer?

 @XmlElement(name = "report_name") public void setName(String name) { this.name = name; } 

Or above the recipient?

 @XmlElement(name = "report_name") public String getName() { return name; } 

I read several JAXB tutorials and have not yet found a consistent template.

+6
source share
1 answer

By default, JAXB impls treats open fields and properties as mapped. You can put the annotation in the get or set method, and the same will apply to it. If you want to annotate the field, you must specify @XmlAccessorType(XAccessType.FIELD) in the class.

Additional Information

+6
source

Source: https://habr.com/ru/post/957394/


All Articles