Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Unmarshal Only</h2> <p>If you are just doing unmarshalling then you can use a <code>StreamReaderDelegate</code> to strip off the numeric suffix.</p> <p><strong>Demo</strong></p> <pre><code>import javax.xml.bind.*; import javax.xml.stream.*; import javax.xml.stream.util.StreamReaderDelegate; import javax.xml.transform.stream.StreamSource; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(HotelRoomDetails.class); XMLInputFactory xif = XMLInputFactory.newFactory(); XMLStreamReader xsr = xif.createXMLStreamReader(new StreamSource("src/forum19834756/input.xml")); xsr = new StreamReaderDelegate(xsr) { @Override public String getLocalName() { String localName = super.getLocalName(); if(localName.startsWith("Night") &amp;&amp; !localName.equals("NightRates")) { return "Night"; } return localName; } }; Unmarshaller unmarshaller = jc.createUnmarshaller(); HotelRoomDetails details = (HotelRoomDetails) unmarshaller.unmarshal(xsr); System.out.println(details.getNightRates().size()); } } </code></pre> <p><strong>HotelRoomDetails</strong></p> <p>Then you have a collection property that maps to the element called <code>Night</code>.</p> <pre><code>import java.util.*; import javax.xml.bind.annotation.*; @XmlRootElement public class HotelRoomDetails { private List&lt;String&gt; nightRates = new ArrayList&lt;String&gt;(); @XmlElementWrapper(name = "NightRates") @XmlElement(name = "Night") public List&lt;String&gt; getNightRates() { return nightRates; } } </code></pre> <hr> <h2>Unmarshal &amp; Marshal</h2> <p><strong>Note:</strong> I'm the <a href="http://www.eclipse.org/eclipselink/moxy.php" rel="nofollow"><strong>EclipseLink JAXB (MOXy)</strong></a> lead and a member of the <a href="http://jcp.org/en/jsr/detail?id=222" rel="nofollow"><strong>JAXB (JSR-222)</strong></a> expert group.</p> <p>If you need to support reading and writing to this format you could use MOXy's <code>@XmlVariableNode</code> extension.</p> <ul> <li><a href="http://blog.bdoughan.com/2013/06/mapping-bad-xml-enumerated-collection.html" rel="nofollow">http://blog.bdoughan.com/2013/06/mapping-bad-xml-enumerated-collection.html</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    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.
    1. VO
      singulars
      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