Note that there are some explanatory texts on larger screens.

plurals
  1. POJAXB ignores HashMap properties?
    primarykey
    data
    text
    <p>I'm using the JAXB implementation that comes with J2SE to serialize a bean that contains a HashMap property. I would assume that this should work out of the box since <a href="http://jaxb.java.net/guide/Mapping_your_favorite_class.html" rel="nofollow">this</a> states</p> <blockquote> <p>JAXB spec defines a special handling for Map when it's used as a propety of a bean. For example, the following bean would produce XMLs like the following: ...</p> </blockquote> <p>This more or less works unless the structure has more than one level, i.e. the HashMap is a property of a bean that is a property of a bean - like this:</p> <pre><code>import java.util.HashMap; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.JAXB; class bean { @XmlElement public HashMap&lt;String,String&gt; map; } @XmlRootElement class b2 { @XmlElement public bean b; } class foo { public static void main(String args[]) { try { bean b = new bean(); b.map = new HashMap&lt;String,String&gt;(); b.map.put("a","b"); b2 two = new b2(); two.b=b; JAXB.marshal(two, System.out); } catch (Exception e) { System.out.println("Exception: " + e.toString()); } } } </code></pre> <p>This outputs <code>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;&lt;b2&gt;&lt;b&gt;&lt;map/&gt;&lt;/b&gt;&lt;/b2&gt;</code> instead of a correctly formatted HashMap. It works if I annotate <code>bean</code> with <code>@XmlRootElement</code> and remove the <code>@XmlElement</code> from <code>map</code>, but I don't see why that should be necessary. Is it supposed to be like that? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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