What is the difference between using @XmlElement before field and before getter declaration?

前端 未结 2 905
春和景丽
春和景丽 2020-12-07 06:39

I can declare JAXB element in two ways:

@XmlElement
public int x;

or

private int x;

@XmlElement
public int getX(){...}
         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-07 07:01

    The use of @XMLElement (and similar annotations) before fields or before getters is well explained in this post: http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html.

    The following annotation before a class determines the XML bindings of fields/getters:

    • @XmlAccessorType(XmlAccessType.PUBLIC_MEMBER): public fields, annotated fields and properties
    • @XmlAccessorType(XmlAccessType.PROPERTY): annotated fields and properties
    • @XmlAccessorType(XmlAccessType.FIELD): fields and annotated properties
    • @XmlAccessorType(XmlAccessType.NONE): annotated fields and annotated properties

提交回复
热议问题