JAXB : Is the annotation @XmlAccessorType is only

2019-02-16 18:16发布

I wanted to know why do we need to specify the Annotation @XmlAccessorType when working with JAXB .

When i googled for this i found out this description from a website stating this @XmlAccessorType sets default field and property serializability. By default, JAXB serializes public fields and properties. By setting @XmlAccessorType, the bean can choose to only allow annotated fields to be serialized.

Here the author mentions that with this annotation it gives control on serialization .

My question is , so @XmlAccessorType has nothing to do with the JAXB Binding and Unbinding from XML to java and java to XML , and it is all about Serialization only .

标签: jaxb
1条回答
干净又极端
2楼-- · 2019-02-16 18:46

JAXB's @XmlAccessorType annotation is only used by JAXB (JSR-222) implementations for determining how to marshal a file to/from XML:

Normally the main decision to be made is between FIELD & PROPERTY/PUBLIC. FIELD is particularly useful when you have logic in your get/set methods that you do not want triggered during marshalling/unmarshalling. To see one way this choice affects the mapping metadata see:

NONE is a useful choice when you have many unmapped properties and you want to tell your JAXB implementation to only map the fields/properties you have annotated. This can be alot easier than adding a lot of @XmlTransient annotations into your model.

Fore More Information

查看更多
登录 后发表回答