Note that there are some explanatory texts on larger screens.

plurals
  1. POSerialize an object with a List member
    primarykey
    data
    text
    <p>Given the following classes:</p> <pre><code>public class Container { private List&lt;SomeData&gt; list; // public getter &amp; setter for list } public class SomeData { private String data; // public getter &amp; setter for data } </code></pre> <p>When I run the following code:</p> <pre><code>import java.beans.XMLEncoder; import java.io.FileOutputStream; SomeData someData1 = new SomeData(); SomeData someData2 = new SomeData(); someData1.setData("data1"); someData2.setData("data2"); List&lt;SomeData&gt; data = new ArrayList&lt;SomeData&gt;(); data.add(someData1); data.add(someData2); Container container = new Container(); container.setList(data); FileOutputStream os = new FileOutputStream("c:\test.xml"); XMLEncoder encoder = new XMLEncoder(os); encoder.writeObject(container); encoder.close(); </code></pre> <p>When I review 'test.xml', there is only data for the container object, and nothing for the SomeData objects in the list (i.e. the strings "data1" &amp; "data2"):</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;java version="1.6.0_22" class="java.beans.XMLDecoder"&gt; &lt;object class="Container"&gt; &lt;void property="container"&gt; &lt;object class="java.util.ArrayList"&gt; &lt;void method="add"&gt; &lt;object class="SomeData"/&gt; &lt;/void&gt; &lt;void method="add"&gt; &lt;object class="SomeData"/&gt; &lt;/void&gt; &lt;/object&gt; &lt;/void&gt; &lt;/object&gt; &lt;/java&gt; </code></pre> <p>How can I serialize 'container' and the SomeData objects stored in the list within 'container'?</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