Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Development/339381"

(Undo revision 257129 by Rick.barkhouse.oracle.com (Talk))
 
Line 1: Line 1:
{{EclipseLink_UserGuide
+
<div style="margin:5px;float:right;border:1px solid #000000;padding:5px">__TOC__</div>
|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 =
+
= Design Documentation: XML 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 properties and 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 structure to hold data for certain mappings.  The mappings that use virtual method access must be defined in EclipseLink OXM metadata.
+
[http://bugs.eclipse.org/339381 ER 339381]
 +
 
 +
Currently, EclipseLink MOXy supports the mapping of Java fields and properties to XML.  Said another way; in order to map data to XML, the user must have an existing Java field or property to map.
 +
 
 +
To support multi-tenancy, we will be allowing the user to add additional mappings at runtime. Because these new mappings would not have existing fields / properties on the Java class to map to, we will introduce the concept of virtual properties, where we can instead rely on special <tt>get()</tt> and <tt>set()</tt> methods to maintain extension data.
 +
 
 +
 
 +
= Requirements =
 +
 
 +
# Users must be able to add new mappings at runtime through EclipseLink OXM
 +
# Users should be able to add any type of MOXy mapping as virtual property
 +
# Users must be able to specify that a Java type virtual access methods, using either Annotations or EclipseLink OXM
 +
 
 +
 
 +
= Configuration =
  
 
In order to add virtual properties to an entity:
 
In order to add virtual properties to an entity:
  
* the Java class must be marked with an '''@XmlVirtualAccessMethods''' annotation, or '''<xml-virtual-access-methods>''' element in OXM
+
* the Java class must be marked with an <tt>@XmlVirtualAccessMethods</tt> annotation, or <tt><xml-virtual-access-methods></tt> element in OXM
 
* the Java class must contain getter and setter methods to access virtual property values
 
* the Java class must contain getter and setter methods to access virtual property values
** '''public Object get(String propertyName)'''
+
** <tt>public Object get(String propertyName)</tt>
** '''public void set(String propertyName, Object value)'''
+
** <tt>public void set(String propertyName, Object value)</tt>
 
** method names are configurable but must have the same method signatures as above
 
** method names are configurable but must have the same method signatures as above
  
Line 26: Line 33:
  
  
== Configuration ==
+
== Annotations ==
  
Virtual Access Methods can be configured either through Java annotations or EclipseLink OXM metadata.
+
The user can specify that a Java class may hold virtual properties by using the <tt>@XmlVirtualAccessMethods</tt> annotation:
  
=== Using Annotations ===
+
<div style="width:900px">
 +
<source lang="java">
 +
@Target({TYPE})
 +
@Retention(RUNTIME)
 +
public @interface XmlVirtualAccessMethods {
 +
 
 +
    /**
 +
    * (Optional) Defines the name of the method used to retrieve virtual properties.
 +
    */
 +
    String getMethod() default "get";
 +
 
 +
    /**
 +
    * (Optional) Defines the name of the method used to store virtual properties.
 +
    */
 +
    String setMethod() default "set";
 +
 
 +
    /**
 +
    * (Optional) Configure the way that virtual properties will appear in generated schemas.<br><br>
 +
    * <b>XmlExtensibleSchema.NODES</b> (default) - Virtual properties will appear as individual nodes<br>
 +
    * <b>XmlExtensibleSchema.ANY</b> - An XSD &lt;any&gt; element will be written to the schema to
 +
    * represent all of the defined virtual properties
 +
    */
 +
    XmlVirtualAccessMethodsSchema schema() default XmlVirtualAccessMethodsSchema.NODES;
 +
 +
}
 +
</source>
 +
</div>
  
 
<div style="width:700px">
 
<div style="width:700px">
 
<source lang="java">
 
<source lang="java">
package example;
+
public enum XmlVirtualAccessMethodsSchema {
 +
    /**
 +
    * Virtual properties are written to the schema as individual nodes (default).
 +
    */
 +
    NODES,
  
import javax.xml.bind.annotation.*;
+
    /**
 +
    * An XML <any> element will be written to the schema to represent all
 +
    * of the defined virtual properties.
 +
    */
 +
    ANY;
 +
}
 +
</source>
 +
</div>
  
import org.eclipse.persistence.oxm.annotations.XmlVirtualAccessMethods;
 
  
 +
== OXM Metadata ==
 +
 +
To indicate an extensions field in EclipseLink OXM, the user can specify an <tt>xml-extensible</tt> element in their metadata file:
 +
 +
<tt>eclipselink_oxm_2_3.xsd</tt>:
 +
<div style="width:850px">
 +
<source lang="java">
 +
...
 +
<xs:element name="java-type">
 +
  <xs:complexType>
 +
      <xs:all>
 +
        ...
 +
        <xs:element ref="xml-virtual-access-methods" minOccurs="0"/>
 +
        ...
 +
 +
...
 +
    <xs:element name="xml-virtual-access-methods">
 +
        <xs:complexType>
 +
            <xs:attribute name="get-method" type="xs:string" default="get" />
 +
            <xs:attribute name="set-method" type="xs:string" default="set" />
 +
            <xs:attribute name="schema" type="xml-virtual-access-methods-schema" default="NODES" />
 +
        </xs:complexType>
 +
    </xs:element>
 +
...
 +
</source>
 +
</div>
 +
 +
 +
== Example ==
 +
 +
The following domain class is annotated with <tt>@XmlVirtualAccessMethods</tt>, indicating that it has special accessor methods to handle additional mappings.  EclipseLink's default behaviour will look for the methods <tt>public Object get(String)</tt> and <tt>public void set(String, Object)</tt> to be the accessors of the virtual property map.
 +
 +
<div style="width:700px">
 +
<source lang="java">
 
@XmlRootElement
 
@XmlRootElement
 
@XmlVirtualAccessMethods
 
@XmlVirtualAccessMethods
 
@XmlAccessorType(AccessType.PROPERTY)
 
@XmlAccessorType(AccessType.PROPERTY)
 
public class Customer {
 
public class Customer {
+
 
 
   private int id;
 
   private int id;
+
 
 
   private String name;
 
   private String name;
+
 
 
   private Map<String, Object> extensions = new HashMap<String, Object>();
 
   private Map<String, Object> extensions = new HashMap<String, Object>();
+
 
 
   public Object get(String name) {
 
   public Object get(String name) {
 
       return extensions.get(name);
 
       return extensions.get(name);
Line 58: Line 135:
 
       extensions.put(name, value);
 
       extensions.put(name, value);
 
   }
 
   }
+
 
 
   @XmlAttribute
 
   @XmlAttribute
 
   public int getId() {
 
   public int getId() {
 
   ...
 
   ...
+
 
 
}
 
}
 
</source>
 
</source>
 
</div>
 
</div>
  
=== Using EclipseLink OXM ===
+
The class above can be expressed in EclipseLink OXM metadata as follows:
  
 
<div style="width:700px">
 
<div style="width:700px">
Line 76: Line 153:
 
       <xml-virtual-access-methods />
 
       <xml-virtual-access-methods />
 
       <java-attributes>
 
       <java-attributes>
         <xml-attribute java-attribute="id"/>
+
         <xml-attribute java-attribute="id" type="java.lang.Integer" />
         <xml-element java-attribute="name"/>
+
         <xml-element java-attribute="name" type="java.lang.String" />
 
       </java-attributes>
 
       </java-attributes>
 
   </java-type>
 
   </java-type>
Line 84: Line 161:
 
</div>
 
</div>
  
 +
In a secondary metadata file, we will define additional mappings that we would like to add to <tt>Customer</tt>:
  
== Example ==
 
 
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 properties by including the '''@XmlVirtualAccessMethods''' annotation (or alternately in OXM).
 
 
Next, we define our virtual mappings in their own EclipseLink OXM file.  Any property encountered in this file that does not have a corresponding Java attribute will be considered a virtual property and will be accessed through the virtual access methods.
 
 
'''virtualprops-oxm.xml'''
 
 
<div style="width:700px">
 
<div style="width:700px">
 
<source lang="xml">
 
<source lang="xml">
Line 107: Line 178:
 
</div>
 
</div>
  
When creating the '''JAXBContext''', we pass in the '''virtualprops''' mappings along with our '''Customer''' class.
+
(Note that there is no special configuration needed for additional mappings; they are specified in the same way as "normal" mappings.)
  
To set the values for virtual properties, we will use the aforementioned '''set()''' method.
+
To set the values for these additional mappings, we will use the aforementioned <tt>set()</tt> method:
  
 
<div style="width:700px">
 
<div style="width:700px">
Line 139: Line 210:
  
  
 
+
== Config Options ==
== XmlAccessorType and XmlTransient ==
+
 
+
If you are using an '''@XmlAccessorType''' other than '''AccessType.PROPERTY''', you will need to mark your virtual properties Map attribute to be '''@XmlTransient''', to prevent the Map itself from being bound to XML.
+
 
+
<div style="width:700px">
+
<source lang="java">
+
package example;
+
 
+
@XmlRootElement
+
@XmlVirtualAccessMethods
+
@XmlAccessorType(AccessType.FIELD)
+
public class Customer {
+
 
+
  @XmlTransient
+
  private Map<String, Object> extensions;
+
  ...
+
</source>
+
</div>
+
 
+
 
+
== Configuration Options ==
+
  
  
 
=== Specifying Alternate Accessor Methods ===
 
=== Specifying Alternate Accessor Methods ===
  
To use different method names as your virtual method accessors, specify them using the '''getMethodName''' and '''setMethodName''' attributes on '''@XmlVirtualAccessMethods''':
+
To use different method names as your extensions accessors, specify them using the <tt>getMethodName</tt> and <tt>setMethodName</tt> attributes on <tt>@XmlExtensible</tt>:
  
 
<div style="width:700px">
 
<div style="width:700px">
 
<source lang="java">
 
<source lang="java">
package example;
 
 
 
@XmlRootElement
 
@XmlRootElement
 
@XmlVirtualAccessMethods(getMethod = "getCustomProps", setMethod = "putCustomProps")
 
@XmlVirtualAccessMethods(getMethod = "getCustomProps", setMethod = "putCustomProps")
Line 222: Line 270:
 
=== Schema Generation Options ===
 
=== Schema Generation Options ===
  
If the user generates an XML Schema from the '''JAXBContext''' after virtual properties have been added, then the resulting schema will obviously be different from any Schema that may have been used to generate the initial domain objects.
+
If the user generates an XML Schema from the <tt>JAXBContext</tt> after virtual properties have been added, then the resulting schema will obviously be different from any Schema that may have been used to generate the initial domain objects.
  
To configure how these new properties should appear in future generated schemas, use the '''schema''' attribute on '''@XmlVirtualAccessMethods'''.
+
To configure how these new properties should appear in future generated schemas, use the <tt>schema</tt> attribute on <tt>@XmlVirtualAccessMethods</tt>.
  
  
Line 233: Line 281:
 
<div style="width:700px">
 
<div style="width:700px">
 
<source lang="java">
 
<source lang="java">
package example;
 
 
 
@XmlRootElement
 
@XmlRootElement
 
@XmlVirtualAccessMethods(schema = XmlVirtualAccessMethodsSchema.NODES)
 
@XmlVirtualAccessMethods(schema = XmlVirtualAccessMethodsSchema.NODES)
Line 246: Line 292:
 
For example:
 
For example:
  
Original '''Customer''' Schema:
+
Original <tt>Customer</tt> Schema:
  
 
<div style="width:700px">
 
<div style="width:700px">
Line 265: Line 311:
 
</div>
 
</div>
  
Generated Schema after adding '''middle-initial''' and '''phone-number''':
+
Generated Schema after adding <tt>middle-initial</tt> and <tt>phone-number</tt>:
  
 
<div style="width:700px">
 
<div style="width:700px">
Line 289: Line 335:
 
'''Virtual Properties in an <any> Element'''
 
'''Virtual Properties in an <any> Element'''
  
EclipseLink can also use an '''<any>''' element to hold all of the virtual properties in one node:
+
EclipseLink can also use an <tt><any></tt> element to hold all of the virtual properties in one node:
  
 
<div style="width:700px">
 
<div style="width:700px">
 
<source lang="java">
 
<source lang="java">
package example;
 
 
 
@XmlRootElement
 
@XmlRootElement
 
@XmlVirtualAccessMethods(schema = XmlVirtualAccessMethodsSchema.ANY)
 
@XmlVirtualAccessMethods(schema = XmlVirtualAccessMethodsSchema.ANY)
Line 323: Line 367:
 
</source>
 
</source>
 
</div>
 
</div>
 +
 +
 +
=== XmlAccessorType and XmlTransient ===
 +
 +
If you are using an <tt>@XmlAccessorType</tt> other than <tt>AccessType.PROPERTY</tt>, you will need to mark your virtual properties Map attribute to be <tt>@XmlTransient</tt>, to prevent the Map itself from being bound to XML.
 +
 +
<div style="width:700px">
 +
<source lang="java">
 +
@XmlRootElement
 +
@XmlVirtualAccessMethods
 +
@XmlAccessorType(AccessType.FIELD)
 +
public class Customer {
 +
 +
  @XmlTransient
 +
  private Map<String, Object> extensions;
 +
  ...
 +
</source>
 +
</div>
 +
 +
 +
= Design =
 +
 +
* <tt>org.eclipse.persistence.jaxb.compiler.Property</tt>
 +
** A Property will now know if it is virtual
 +
* <tt>org.eclipse.persistence.jaxb.compiler.TypeInfo</tt>
 +
** A TypeInfo will now know if it contains virtual properties
 +
* <tt>org.eclipse.persistence.jaxb.compiler.XMLProcessor</tt>
 +
** When processing an OXM file, if a Property is encountered (e.g. "foo") that does not have a corresponding property in Java:
 +
*** If the TypeInfo has virtual properties enabled, then create a new "foo" Property, and setup an <tt>org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor</tt> for its mapping
 +
*** If the TypeInfo does not virtual properties enabled, a "No such property exists" exception will be thrown
 +
 +
 +
= Document History =
 +
{|{{BMTableStyle}}
 +
|-{{BMTHStyle}}
 +
! Date
 +
! Author
 +
! Version Description & Notes
 +
|-
 +
| 110323
 +
| Rick Barkhouse
 +
| 1.00
 +
|-
 +
| 110329
 +
| Rick Barkhouse
 +
| 1.01 : Input from Doug, added Action Items
 +
|-
 +
| 110331
 +
| Rick Barkhouse
 +
| 1.02 : Moved open items to Discussion page
 +
|-
 +
| 110404
 +
| Rick Barkhouse
 +
| 1.03 : Changed to "XML Flex Extensions", modified OXM configuration
 +
|-
 +
| 110406
 +
| Rick Barkhouse
 +
| 1.04 : Changed to "XML Extensions", added Schema Generation section
 +
|-
 +
| 110407
 +
| Rick Barkhouse
 +
| 1.05 : Added XmlExtensionSchemaGenerationPolicy information
 +
|-
 +
| 110413
 +
| Rick Barkhouse
 +
| 1.06 : Modified document to reflect new @XmlExtensible design
 +
|-
 +
| 110517
 +
| Rick Barkhouse
 +
| 1.10 : Final design, renamed to @XmlVirtualAccessMethods
 +
|}<br>

Latest revision as of 12:15, 21 June 2011

Design Documentation: XML Virtual Access Methods

ER 339381

Currently, EclipseLink MOXy supports the mapping of Java fields and properties to XML. Said another way; in order to map data to XML, the user must have an existing Java field or property to map.

To support multi-tenancy, we will be allowing the user to add additional mappings at runtime. Because these new mappings would not have existing fields / properties on the Java class to map to, we will introduce the concept of virtual properties, where we can instead rely on special get() and set() methods to maintain extension data.


Requirements

  1. Users must be able to add new mappings at runtime through EclipseLink OXM
  2. Users should be able to add any type of MOXy mapping as virtual property
  3. Users must be able to specify that a Java type virtual access methods, using either Annotations or EclipseLink OXM


Configuration

In order to add virtual properties to an entity:

  • the Java class must be marked with an @XmlVirtualAccessMethods annotation, or <xml-virtual-access-methods> element in OXM
  • the Java class must contain getter and setter methods to access virtual property values
    • public Object get(String propertyName)
    • public void set(String propertyName, Object value)
    • method names are configurable but must have the same method signatures as above


Idea.png
By default, EclipseLink will look for methods named "set" and "get". To customize accessor method names, see Specifying Alternate Accessor Methods.


Annotations

The user can specify that a Java class may hold virtual properties by using the @XmlVirtualAccessMethods annotation:

@Target({TYPE}) 
@Retention(RUNTIME)
public @interface XmlVirtualAccessMethods {
 
    /**
     * (Optional) Defines the name of the method used to retrieve virtual properties.
     */
    String getMethod() default "get";
 
    /**
     * (Optional) Defines the name of the method used to store virtual properties.
     */
    String setMethod() default "set";
 
    /**
     * (Optional) Configure the way that virtual properties will appear in generated schemas.<br><br>
     * <b>XmlExtensibleSchema.NODES</b> (default) - Virtual properties will appear as individual nodes<br>
     * <b>XmlExtensibleSchema.ANY</b> - An XSD &lt;any&gt; element will be written to the schema to 
     * represent all of the defined virtual properties
     */
    XmlVirtualAccessMethodsSchema schema() default XmlVirtualAccessMethodsSchema.NODES;
 
}
public enum XmlVirtualAccessMethodsSchema {
    /**
     * Virtual properties are written to the schema as individual nodes (default).
     */
    NODES,
 
    /**
     * An XML <any> element will be written to the schema to represent all
     * of the defined virtual properties.
     */
    ANY;
}


OXM Metadata

To indicate an extensions field in EclipseLink OXM, the user can specify an xml-extensible element in their metadata file:

eclipselink_oxm_2_3.xsd:

...
<xs:element name="java-type">
   <xs:complexType>
      <xs:all>
         ...
         <xs:element ref="xml-virtual-access-methods" minOccurs="0"/>
         ...
 
...
    <xs:element name="xml-virtual-access-methods">
        <xs:complexType>
            <xs:attribute name="get-method" type="xs:string" default="get" />
            <xs:attribute name="set-method" type="xs:string" default="set" />
            <xs:attribute name="schema" type="xml-virtual-access-methods-schema" default="NODES" />
        </xs:complexType>
    </xs:element>
...


Example

The following domain class is annotated with @XmlVirtualAccessMethods, indicating that it has special accessor methods to handle additional mappings. EclipseLink's default behaviour will look for the methods public Object get(String) and public void set(String, Object) to be the accessors of the virtual property map.

@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() {
   ...
 
}

The class above can be expressed in EclipseLink OXM metadata as follows:

...
<java-types>
   <java-type name="Customer">
      <xml-virtual-access-methods />
      <java-attributes>
         <xml-attribute java-attribute="id" type="java.lang.Integer" />
         <xml-element java-attribute="name" type="java.lang.String" />
      </java-attributes>
   </java-type>
...

In a secondary metadata file, we will define additional mappings that we would like to add to Customer:

...
<java-types>
    <java-type name="Customer">
        <java-attributes>
            <xml-element java-attribute="discountCode" name="discount-code"
                type="java.lang.String" />
        </java-attributes>
    </java-type>
</java-types>
...

(Note that there is no special configuration needed for additional mappings; they are specified in the same way as "normal" mappings.)

To set the values for these additional mappings, we will use the aforementioned set() method:

InputStream oxm = classLoader.getResourceAsStream("eclipselink-oxm.xml");
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, oxm);
 
Class[] classes = new Class[] { Customer.class };
JAXBContext ctx = JAXBContext.newInstance(classes, properties);
 
Customer c = new Customer();
c.setName("Dan Swano");
c.set("discountCode", "SIUB372JS7G2IUDS7");
 
ctx.createMarshaller().marshal(e, System.out);

This will produce the following XML:

<customer name="Dan Swano">
   <discount-code>SIUB372JS7G2IUDS7</discount-code>
</customer>


Config Options

Specifying Alternate Accessor Methods

To use different method names as your extensions accessors, specify them using the getMethodName and setMethodName attributes on @XmlExtensible:

@XmlRootElement
@XmlVirtualAccessMethods(getMethod = "getCustomProps", setMethod = "putCustomProps")
@XmlAccessorType(AccessType.FIELD)
public class Customer {
 
   @XmlAttribute
   private int id;
 
   private String name;
 
   @XmlTransient
   private Map<String, Object> extensions;
 
   public Object getCustomProps(String name) {
      if (extensions == null) {
         extensions = new HashMap<String, Object>();
      }
      return extensions.get(name);
   }
 
   public void putCustomProps(String name, Object value) {
      if (extensions == null) {
         extensions = new HashMap<String, Object>();
      }
      extensions.put(name, value);
   }
 
}

In OXM:

...
<java-types>
   <java-type name="Customer">
      <xml-virtual-access-methods get-method="getCustomProps" set-method="putCustomProps" />
      <java-attributes>
         <xml-attribute java-attribute="id" type="java.lang.Integer" />
         <xml-element java-attribute="name" type="java.lang.String" />
      </java-attributes>
   </java-type>
...


Schema Generation Options

If the user generates an XML Schema from the JAXBContext after virtual properties have been added, then the resulting schema will obviously be different from any Schema that may have been used to generate the initial domain objects.

To configure how these new properties should appear in future generated schemas, use the schema attribute on @XmlVirtualAccessMethods.


Virtual Properties as individual Nodes

This is EclipseLink's default behaviour, or can be specified explicitly as an override as follows:

@XmlRootElement
@XmlVirtualAccessMethods(schema = XmlVirtualAccessMethodsSchema.NODES)
@XmlAccessorType(AccessType.FIELD)
public class Customer {
 
   ...

For example:

Original Customer Schema:

<xs:schema ...>
 
    <xs:element name="customer">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="first-name" type="xs:string" />
                <xs:element name="last-name" type="xs:string" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
 
</xs:schema>

Generated Schema after adding middle-initial and phone-number:

<xs:schema ...>
 
    <xs:element name="customer">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="first-name" type="xs:string" />
                <xs:element name="last-name" type="xs:string" />
                <xs:element name="middle-initial" type="xs:string" />
                <xs:element name="phone-number" type="xs:string" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
 
</xs:schema>


Virtual Properties in an <any> Element

EclipseLink can also use an <any> element to hold all of the virtual properties in one node:

@XmlRootElement
@XmlVirtualAccessMethods(schema = XmlVirtualAccessMethodsSchema.ANY)
@XmlAccessorType(AccessType.FIELD)
public class Customer {
 
   ...

Taking the example from above, a newly generated schema using this approach would look like:

<xs:schema ...>
 
    <xs:element name="customer">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="first-name" type="xs:string" />
                <xs:element name="last-name" type="xs:string" />
                <xs:any minOccurs="0" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>
 
</xs:schema>


XmlAccessorType and XmlTransient

If you are using an @XmlAccessorType other than AccessType.PROPERTY, you will need to mark your virtual properties Map attribute to be @XmlTransient, to prevent the Map itself from being bound to XML.

@XmlRootElement
@XmlVirtualAccessMethods
@XmlAccessorType(AccessType.FIELD)
public class Customer {
 
   @XmlTransient
   private Map<String, Object> extensions;
   ...


Design

  • org.eclipse.persistence.jaxb.compiler.Property
    • A Property will now know if it is virtual
  • org.eclipse.persistence.jaxb.compiler.TypeInfo
    • A TypeInfo will now know if it contains virtual properties
  • org.eclipse.persistence.jaxb.compiler.XMLProcessor
    • When processing an OXM file, if a Property is encountered (e.g. "foo") that does not have a corresponding property in Java:
      • If the TypeInfo has virtual properties enabled, then create a new "foo" Property, and setup an org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor for its mapping
      • If the TypeInfo does not virtual properties enabled, a "No such property exists" exception will be thrown


Document History

Date Author Version Description & Notes
110323 Rick Barkhouse 1.00
110329 Rick Barkhouse 1.01 : Input from Doug, added Action Items
110331 Rick Barkhouse 1.02 : Moved open items to Discussion page
110404 Rick Barkhouse 1.03 : Changed to "XML Flex Extensions", modified OXM configuration
110406 Rick Barkhouse 1.04 : Changed to "XML Extensions", added Schema Generation section
110407 Rick Barkhouse 1.05 : Added XmlExtensionSchemaGenerationPolicy information
110413 Rick Barkhouse 1.06 : Modified document to reflect new @XmlExtensible design
110517 Rick Barkhouse 1.10 : Final design, renamed to @XmlVirtualAccessMethods

Back to the top