|
|
(348 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
− | {{EclipseLink_UserGuide
| |
− | |eclipselink=y
| |
− | |eclipselinktype=MOXy
| |
− | |info=y
| |
− | |api=y
| |
− | |apis= * [http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/oxm/annotations/XmlVirtualAccessMethods.html XmlVirtualAccessMethods]
| |
− | |toc=y
| |
− | }}
| |
| | | |
− | = Virtual Access Methods =
| |
− |
| |
− | In addition to the standard JAXB access methods (public member, field, property, etc.), EclipseLink MOXy 2.3 introduces the concept of "virtual access methods", which instead rely on special '''get()''' and '''set()''' methods to maintain mapping data. For example, you might want to use a '''HashMap''' as the underlying data structure to hold all of your mapping data.
| |
− |
| |
− |
| |
− | == Example Model ==
| |
− |
| |
− | For this example we will use the following '''Employee''' class. In addition to some conventional JAXB mappings, we also specify that this class contains virtual access methods by including the '''@XmlVirtualAccessMethods''' annotation.
| |
− |
| |
− | <source lang="java">
| |
− | @XmlRootElement
| |
− | @XmlVirtualAccessMethods
| |
− | @XmlAccessorType(AccessType.PROPERTY)
| |
− | public class Customer {
| |
− |
| |
− | private int id;
| |
− |
| |
− | private String name;
| |
− |
| |
− | private Map<String, Object> extensions = new HashMap<String, Object>();
| |
− |
| |
− | public Object get(String name) {
| |
− | return extensions.get(name);
| |
− | }
| |
− |
| |
− | public void set(String name, Object value) {
| |
− | extensions.put(name, value);
| |
− | }
| |
− |
| |
− | @XmlAttribute
| |
− | public int getId() {
| |
− | ...
| |
− |
| |
− | }
| |
− | </source>
| |