Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAXB : Is the annotation @XmlAccessorType is only for Serialization and nothing to do with Binding of data?

Tags:

jaxb

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 .

like image 852
Pawan Avatar asked Apr 04 '12 14:04

Pawan


1 Answers

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:

  • http://blog.bdoughan.com/2012/02/jaxbs-xmltype-and-proporder.html

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

  • http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html
like image 127
bdoughan Avatar answered Oct 01 '22 06:10

bdoughan