Jump to: navigation, search

Difference between revisions of "EclipseLink/DesignDocs/406697"

(Example)
Line 21: Line 21:
  
 
== Example ==
 
== Example ==
 +
 +
<source lang="java">
 +
@XmlRootElement
 +
public class Root {
 +
 +
public String name;
 +
 +
@XmlVariableNode(attributeName="thingName")
 +
public List<Thing> things;
 +
}
 +
 +
public class Thing {
 +
public String thingName;
 +
public String thingValue;
 +
}
 +
 +
</source>
 +
<source lang="java">
 +
Root r = new Root();
 +
r.name = "theRootName";
 +
r.things = new ArrayList<Thing>();
 +
Thing thing1 = new Thing();
 +
thing1.thingName = "thinga";
 +
thing1.thingValue = "thingavalue";
 +
 +
Thing thing2 = new Thing();
 +
thing2.thingName = "thingb";
 +
thing2.thingValue = "thingbvalue";
 +
 +
Thing thing3 = new Thing();
 +
thing3.thingName = "thingc";
 +
thing3.thingValue = "thingcvalue";
 +
r.things.add(thing1);
 +
r.things.add(thing2);
 +
r.things.add(thing3);
 +
 +
</source>
 +
<source lang="java">
 +
marshaller.marshal(r, System.out)
 +
<root>
 +
  <name>theRootName</name>
 +
  <thinga>
 +
      <thingName>thinga</thingName>
 +
      <thingValue>thingavalue</thingValue>
 +
  </thinga>
 +
  <thingb>
 +
      <thingName>thingb</thingName>
 +
      <thingValue>thingbvalue</thingValue>
 +
  </thingb>
 +
  <thingc>
 +
      <thingName>thingc</thingName>
 +
      <thingValue>thingcvalue</thingValue>
 +
  </thingc>
 +
</root>
 +
</source>
  
 
== Design  ==
 
== Design  ==

Revision as of 14:51, 26 April 2013

Document History

  • April 26, 2013 - Initial Draft

Requirements

API

The following annotation will be added
org.eclipse.persistence.oxm.annotations.XmlVariableNode

@Target({METHOD, FIELD})
@Retention(RUNTIME)
public @interface XmlVariableNode {
    String attributeName();
}

Example

@XmlRootElement
public class Root {
 
	public String name;
 
	@XmlVariableNode(attributeName="thingName")
	public List<Thing> things;
}
 
public class Thing {
	public String thingName;
	public String thingValue;
}
Root r = new Root();
r.name = "theRootName";
r.things = new ArrayList<Thing>();
Thing thing1 = new Thing();
thing1.thingName = "thinga";
thing1.thingValue = "thingavalue";
 
Thing thing2 = new Thing();
thing2.thingName = "thingb";
thing2.thingValue = "thingbvalue";
 
Thing thing3 = new Thing();
thing3.thingName = "thingc";
thing3.thingValue = "thingcvalue";
r.things.add(thing1);
r.things.add(thing2);
r.things.add(thing3);
marshaller.marshal(r, System.out)
<root>
   <name>theRootName</name>
   <thinga>
       <thingName>thinga</thingName>
       <thingValue>thingavalue</thingValue>
   </thinga>
   <thingb>
       <thingName>thingb</thingName>
       <thingValue>thingbvalue</thingValue>
   </thingb>
   <thingc>
       <thingName>thingc</thingName>
       <thingValue>thingcvalue</thingValue>
   </thingc>
</root>

Design

A new mapping will be created XMLVariableXPathMapping and it will extend the AnyCollectionMapping

Note/Issues

  • inheritance
  • List<Object>
  • single case ie:not on a collection
  • external bindings