Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Note:</strong> I'm the <a href="http://www.eclipse.org/eclipselink/moxy.php" rel="nofollow"><strong>EclipseLink JAXB (MOXy)</strong></a> lead and a member of the <a href="http://jcp.org/en/jsr/detail?id=222" rel="nofollow"><strong>JAXB (JSR-222)</strong></a> expert group.</p> <p>You may be interested in the <code>@XmlNamedObjectGraph</code> extension we have added in EclipseLink 2.5.0. It allows you to define multiple views on your domain model. You can try this out today using a nightly build:</p> <ul> <li><a href="http://www.eclipse.org/eclipselink/downloads/nightly.php" rel="nofollow">http://www.eclipse.org/eclipselink/downloads/nightly.php</a></li> </ul> <p>Below I'll give an example:</p> <p><strong>Test</strong></p> <p>The <code>@XmlNamedObjectGraph</code> annotation is used to define subsets of the object graph that can be used when marshalling and unmarshalling.</p> <pre class="lang-java prettyprint-override"><code>import javax.xml.bind.annotation.*; import org.eclipse.persistence.oxm.annotations.*; @XmlNamedObjectGraph( name="only def", attributeNodes = { @XmlNamedAttributeNode("def") } ) @XmlRootElement public class Test { private String abc; private String def; public String getAbc() { return abc; } public void setAbc(String abc) { this.abc = abc; } public String getDef() { return def; } public void setDef(String def) { this.def = def; } } </code></pre> <p><strong>Demo</strong></p> <p>The <code>MarshallerProperties.OBJECT_GRAPH</code> can be used to specify which object graph should be marshallled.</p> <pre class="lang-java prettyprint-override"><code>import javax.xml.bind.*; import org.eclipse.persistence.jaxb.MarshallerProperties; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Test.class); Test test = new Test(); test.setAbc("FOO"); test.setDef("BAR"); Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); // Marshal the Entire Object marshaller.marshal(test, System.out); // Marshal Only What is Specified in the Object Graph marshaller.setProperty(MarshallerProperties.OBJECT_GRAPH, "only def"); marshaller.marshal(test, System.out); } } </code></pre> <p><strong>Output</strong></p> <p>Below is the output from running the demo code. The first time the instance of <code>Test</code> is marshalled it contains all the properties and the second time just the <code>def</code> property.</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;test&gt; &lt;abc&gt;FOO&lt;/abc&gt; &lt;def&gt;BAR&lt;/def&gt; &lt;/test&gt; &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;test&gt; &lt;def&gt;BAR&lt;/def&gt; &lt;/test&gt; </code></pre> <p><strong>For More Information</strong></p> <ul> <li><a href="http://blog.bdoughan.com/2013/03/moxys-object-graphs-inputoutput-partial.html" rel="nofollow">http://blog.bdoughan.com/2013/03/moxys-object-graphs-inputoutput-partial.html</a></li> <li><a href="http://blog.bdoughan.com/2013/03/moxys-object-graphs-partial-models-on.html" rel="nofollow">http://blog.bdoughan.com/2013/03/moxys-object-graphs-partial-models-on.html</a></li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload