What's the difference between JAXB annotations put on getter versus setters versus members?

前端 未结 2 1619
闹比i
闹比i 2021-02-07 02:01

Title says it all.

I would like to know what is the principial difference between putting JAXB annotation (like @XmlElement) on field / getter / setter. It

2条回答
  •  死守一世寂寞
    2021-02-07 02:31

    By default JAXB impls will treat properties (get/set pairs), public fields (instance variables), and annotated non-public fields as mapped. If you just annotate a field you will get a duplicate mapped property exception.

    If you want to annotate the field you should specify @XmlAccessorType(XmlAccessType.FIELD) on the class.

    For More Information

    • http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html

提交回复
热议问题