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/UserGuide/MOXy/Simple Values/Multiple Mappings"

(New page: {{EclipseLink_UserGuide |info=y |toc=y |api=n }} = Multiple Mappings for a Single Property = Standard JAXB can have at most one mapping per Java field. Since EclipseLink MOXy 2.3, multi...)
 
m (Replacing page with 'See http://www.eclipse.org/eclipselink/documentation/2.4/moxy/simple_values003.htm')
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{EclipseLink_UserGuide
+
See http://www.eclipse.org/eclipselink/documentation/2.4/moxy/simple_values003.htm
|info=y
+
|toc=y
+
|api=n
+
}}
+
 
+
= Multiple Mappings for a Single Property =
+
 
+
Standard JAXB can have at most one mapping per Java field.  Since EclipseLink MOXy 2.3, multiple mappings can be created for a single property using OXM metadata, with the caveat that at most one mapping will be readable (the rest will be "write-only").
+
 
+
 
+
== Example ==
+
 
+
This example will use the following Java class:
+
 
+
<source lang="java">
+
package example;
+
 
+
import javax.xml.bind.annotation.*;
+
 
+
@XmlRootElement
+
@XmlAccessorType(XmlAccessType.FIELD)
+
public class CustomQuoteRequest {
+
 
+
  private int requestId;
+
 
+
  private String currencyPairCode;
+
 
+
}
+
</source>
+
 
+
The example below shows how to to define multiple mappings for the '''currencyPairCode''' in EclipseLink's OXM metadata format. Note that the second mapping has specified '''write-only="true"'''.
+
 
+
<source lang="xml">
+
...
+
<java-type name="CustomQuoteRequest">
+
  <xml-root-element/>
+
  <java-attributes>
+
      <xml-element java-attribute="requestId" name="id"/>
+
      <xml-attribute java-attribute="currencyPairCode" xml-path="req/info/instrmt/@sym"/>
+
      <xml-attribute java-attribute="currencyPairCode" xml-path="req/info/leg/token/@sym" write-only="true"/>         
+
  </java-attributes>
+
</java-type>
+
...
+
</source>
+
 
+
 
+
== XML Output ==
+
 
+
The output below shows an example '''CustomQuoteRequest''' marshalled to XML.
+
 
+
<source lang="xml">
+
<?xml version="1.0" encoding="UTF-8"?>
+
<customQuoteRequest>
+
  <id>881</id>
+
  <req>
+
      <info>
+
        <instrmt sym="CAD/USD"/>
+
        <leg>
+
            <token sym="CAD/USD"/>
+
        </leg>
+
      </info>
+
  </req>
+
</customQuoteRequest>
+
</source>
+

Latest revision as of 10:42, 8 November 2012

See http://www.eclipse.org/eclipselink/documentation/2.4/moxy/simple_values003.htm

Back to the top