Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Any <a href="http://jcp.org/en/jsr/detail?id=222" rel="nofollow"><strong>JAXB (JSR-222)</strong></a> implementation (including <a href="http://www.eclipse.org/eclipselink/moxy.php" rel="nofollow"><strong>EclipseLink MOXy</strong></a>) can keep free from information as a DOM structure. You could use an <code>XmlAdapter</code> to convert that DOM structure to/from a Map.</p> <p><strong>XmlAdapter (DomMapAdapter)</strong></p> <p>Below is a skeleton for the <code>XmlAdapter</code>, I haven't actually included the logic for converting between a <code>java.util.Map</code> and <code>org.w3c.dom.Document</code>.</p> <pre><code>import java.util.*; import javax.xml.bind.annotation.adapters.XmlAdapter; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.*; public class DomMapAdapter extends XmlAdapter&lt;Object, Map&lt;String, Object&gt;&gt; { private Document document; public DomMapAdapter() { try { document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); } catch(Exception e) { throw new RuntimeException(e); } } @Override public Map&lt;String, Object&gt; unmarshal(Object v) throws Exception { Document document = (Document) v; Map&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;(); // TODO - Convert Document to Map return map; } @Override public Object marshal(Map&lt;String, Object&gt; v) throws Exception { // TODO - Convert Map to Document return document; } } </code></pre> <p><strong>Model</strong></p> <p>Below is how you specify the <code>XmlAdapter</code> using the <code>XmlJavaTypeAdapter</code> annotation.</p> <pre><code>import java.util.Map; import javax.xml.bind.annotation.*; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; @XmlRootElement @XmlAccessorType(XmlAccessType.FIELD) public class Model { @XmlJavaTypeAdapter(DomMapAdapter.class) private Map&lt;String, Object&gt; data; } </code></pre> <hr> <p>I have entered the following enhancement request that would make this use case easier. Please add any information that you feel would be helpful:</p> <ul> <li><a href="http://bugs.eclipse.org/407196" rel="nofollow">http://bugs.eclipse.org/407196</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