Note that there are some explanatory texts on larger screens.

plurals
  1. PODeserializing XML text elements with attributes in XStream
    primarykey
    data
    text
    <p>Basically, I want to do the reverse of <a href="https://stackoverflow.com/questions/1726863/xstream-node-with-attributes-and-text-node">this question</a>.</p> <p>I'm getting XML from Microsoft's Bing batch Geocode service, and some of the elements look like this (poached from <a href="http://msdn.microsoft.com/en-us/library/ff701730.aspx" rel="nofollow noreferrer">here</a>):</p> <pre><code>&lt;DataflowJob&gt; &lt;Id&gt;5bf10c37df944083b1879fbb0556e67e&lt;/Id&gt; &lt;Link role="self"&gt;https://spatial.virtualearth.net /REST/v1/dataflows/Geocode/5bf10c37df944083b1879fbb0556e67e&lt;/Link&gt; &lt;Link role="output" name="succeeded"&gt;https://spatial.virtualearth.net/REST/v1/dataflows/Geocode/5bf10c37df944083b1879fbb0556e67e/output/succeeded&lt;/Link&gt; &lt;Link role="output" name="failed"&gt;https://spatial.virtualearth.net/REST/v1/dataflows/Geocode/5bf10c37df944083b1879fbb0556e67e/output/failed&lt;/Link&gt; &lt;Description&gt;Xml&lt;/Description&gt; &lt;Status&gt;Completed&lt;/Status&gt; ... &lt;/DataflowJob&gt; </code></pre> <p>Notice that the <code>&lt;Link&gt;</code> elements have attributes as well as text content. Here are the relevant POJO classes I'm trying to deserialize to:</p> <pre><code>class DataflowJob { String Id; @XStreamImplicit List&lt;Link&gt; Links; String Description; Status Status; ... } class Link { @XStreamAsAttribute Role role; @XStreamAsAttribute Name name; String url; } </code></pre> <p>With my current configuration (classes are aliased, attributes auto-detected, and all that jazz), XStream properly deserializes the <code>Name</code> and <code>Role</code> attributes on the <code>&lt;Link&gt;</code> elements, but not the actual link text itself.</p> <p>How do I get XStream to deserialize that text into a <code>String</code> field in a <code>Link</code> object?</p> <p>I don't want to have to manually insert new elements around the link text* just for this.</p> <hr> <p>*e.g., replace</p> <pre><code>&lt;Link role="self"&gt; https://long/url/here &lt;/Link&gt; </code></pre> <p>with</p> <pre><code>&lt;Link role="self"&gt; &lt;url&gt;https://long/url/here&lt;/url&gt; &lt;/Link&gt; </code></pre>
    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.
 

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