aspose file tools*
The moose likes Web Services and the fly likes XmlAccessType.FIELD definition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "XmlAccessType.FIELD definition" Watch "XmlAccessType.FIELD definition" New topic
Author

XmlAccessType.FIELD definition

steve claflin
Ranch Hand

Joined: Dec 04, 2008
Posts: 54
I'm a bit puzzled by this one. The docs rather glibly say:

Every non static, non transient field in a JAXB-bound class will be automatically bound to XML, unless annotated by XmlTransient. Getter/setter pairs are bound to XML only when they are explicitly annotated by some of the JAXB annotations.

Which leaves me wondering when compared to the other enum values, "if the field isn't public, and doesn't have a getter/setter pair, then how will the code get to the value?"

Options I've considered include:

1. private element, with a get OR set method, but not both, for one-way conversion. The examples I've seen seem to all have a private field with a get method but no set method. If this is the case, then is private field with only a set method OK as well, for XML to Java conversion only?

2. protected field, and somehow an adapter class gets created which exposes the field with public methods

Or could it be something else entirely?
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
I would prefer to write some code to test this, but don't have time at the moment, so I can just contribute another guess:
Which leaves me wondering when compared to the other enum values, "if the field isn't public, and doesn't have a getter/setter pair, then how will the code get to the value?"

I am guessing that JAXB uses reflection to set the value of the field when marshalling XML to Java objects. The application code would then use the getter method of the field to retrieve the value, which in effect is immutable, as far as the application is concerned (assuming there is no setter method, of course).
Best wishes!
steve claflin
Ranch Hand

Joined: Dec 04, 2008
Posts: 54
That's another option I hadn't thought of. I had forgotten that reflection can access private elements without using a getter or setter.

I'm in the same boat as far as not being able to write up a test at the moment, but this is another thing I can look for in the generated classes when I do.
 
wood burning stoves
 
subject: XmlAccessType.FIELD definition