Comprehensive Un-Marshalling with JAX-RS Jersey (List of Lists)

I am trying to find the best way to decouple some data from the open API (which means I have no control over how it is serialized to XML).

<Show>
 <name>Buffy the Vampire Slayer</name>
 <totalseasons>7</totalseasons>
 <Episodelist>
  <Season no="1">
   <episode>...</episode>
   <episode>...</episode>
   <episode>...</episode>
   <episode>...</episode>
  </Season>
  <Season no="2">...</Season>
  <Season no="3">...</Season>
 </Episodelist>
</Show>

      

Above is an example of the XML returned from a ReSTful request. Ideally I would like to figure out how to do two things; 1) combine all seasonal listings into one episode list and 2) is it possible to access only child elements and ignore parent elements when unpacking the XML (e.g. only Access EpisodeList, ignoring Show)?

Thanks for any help! This is my first SO post (still pretty new to programming).

+3


source to share


1 answer


In the end, I created several "helper" classes to retrieve the data I needed. I wrote a getEpisodeList method on the EpisodeListHelper that translates all episodes into one list.

EpisodeListHelper Class

@XmlRootElement(name="Show")
@XmlAccessorType(XmlAccessType.FIELD)
public class EpisodeListHelper {
    @XmlElementWrapper(name="Episodelist")
    @XmlElement(name="Season")
    private List<SeasonHelper> seasonList;
...
}

      



SeasonHelper class

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class SeasonHelper {
    @XmlElement(name="episode")
    private List<Episode> list;
...
}

      

0


source







All Articles