Note that there are some explanatory texts on larger screens.

plurals
  1. PODeserializing XML in Android using X-Stream
    primarykey
    data
    text
    <p><em>SOLVED</em> Changed Contents contents to:</p> <pre><code>// Lists @XStreamImplicit(itemFieldName = "Contents") public List&lt;Contents&gt; Contents = new ArrayList&lt;Contents&gt;(); </code></pre> <p>I'm trying to deserialize the following XML:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;Items&gt; &lt;Item&gt; &lt;type&gt;Test&lt;/type&gt; &lt;uid&gt;1&lt;/uid&gt; &lt;depends&gt;1&lt;/depends&gt; &lt;catid&gt;1&lt;/catid&gt; &lt;label&gt;Test&lt;/label&gt; &lt;defaultVal&gt;default&lt;/defaultVal&gt; &lt;answer&gt;Test&lt;/answer&gt; &lt;Contents&gt; &lt;Content&gt; &lt;uid&gt;1&lt;/uid&gt; &lt;label&gt;Test&lt;/label&gt; &lt;/Content&gt; &lt;/Contents&gt; &lt;/Item&gt; &lt;/Items&gt; </code></pre> <p>The problem is that when I reach Contents it crashes due to going deeper by another level.</p> <p>This is how i DeSerialize my XML, it works without the contents.</p> <pre><code>public static Object DeSerializeFromXML(String xml, Class items, Class item) { XStream xstream = new XStream(); xstream.processAnnotations(new Class[] { items, item }); return xstream.fromXML(xml); } </code></pre> <p>Here's how I call the DeSerialize method:</p> <pre><code>Items reader = (Items)Data.Serialization.Instance().DeSerializeFromXML(xml, Items.class, Item.class); </code></pre> <p>And as last my Objects:</p> <p>Items.cs</p> <pre><code>@XStreamAlias("Items") public class Items { public Items() { items = new ArrayList&lt;Item&gt;(); } @XStreamImplicit(itemFieldName = "Item") public List&lt;Item&gt; items = new ArrayList&lt;Item&gt;(); } </code></pre> <p>Item.cs</p> <pre><code>@XStreamAlias("Item") public class Item { // Type public String type = ""; // Ids public int uid = 0; public int catid = 0; public int depends = 0; // Values public String label = ""; public String defaultVal = ""; public String answer = ""; // Lists public Contents content; public Item() { } public Item(String type, int uid, int catid, int depends, String label, String defaultval, String answer) { this.type = type; this.uid = uid; this.catid = catid; this.depends = depends; this.label = label; this.defaultVal = defaultval; this.answer = answer; content = new Contents(); } @XStreamAlias("Contents") public static class Contents { public Contents() { contents = new ArrayList&lt;Content&gt;(); } @XStreamImplicit(itemFieldName = "Content") public List&lt;Content&gt; contents = new ArrayList&lt;Content&gt;(); } </code></pre> <p>Content.cs</p> <pre><code>@XStreamAlias("Content") public class Content { public int uid = 0; public String label = ""; public Content() { } public Content(int uid, String label) { this.uid = uid; this.label = label; } </code></pre> <p>I'm not quite sure if my annotations for the next level are correct. Any help is appreciated.</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.
 

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