title: JAX-RS/Jackson -- Deserialize JSON with Unknown Root Element Name?
body: <p>I am writing a RESTeasy Proxy Client to consume <a href="https://www.apple.com/itunes/affiliates/resources/documentation/genre-mapping.html" rel="nofollow">Apple's API</a> for retrieving their iTunes category list.  When you query for information about a given category , for example with this URL:</p>
  
  <pre><code>https://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/genres?id=1420
  </code></pre>
  
  <p>...you get a JSON response that looks like this:</p>
  
  <pre><code>{  
     "1420":{  
        "name":"Self-Help",
        "id":"1420",
        "url":"https://itunes.apple.com/us/genre/podcasts-health-self-help/id1420?mt=2",
        "rssUrls":{  
           "topVideoPodcastEpisodes":"https://itunes.apple.com/us/rss/topvideopodcastepisodes/genre=1420/json",
           "topAudioPodcasts":"https://itunes.apple.com/us/rss/topaudiopodcasts/genre=1420/json",
           "topVideoPodcasts":"https://itunes.apple.com/us/rss/topvideopodcasts/genre=1420/json",
           "topPodcasts":"https://itunes.apple.com/us/rss/toppodcasts/genre=1420/json",
           "topAudioPodcastEpisodes":"https://itunes.apple.com/us/rss/topaudiopodcastepisodes/genre=1420/json",
           "topPodcastEpisodes":"https://itunes.apple.com/us/rss/toppodcastepisodes/genre=1420/json"
        },
        "chartUrls":{  
           "videoPodcastEpisodes":"https://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/charts?cc=us&amp;g=1420&amp;name=VideoPodcastEpisodes",
           "podcasts":"https://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/charts?cc=us&amp;g=1420&amp;name=Podcasts",
           "audioPodcastEpisodes":"https://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/charts?cc=us&amp;g=1420&amp;name=AudioPodcastEpisodes",
           "audioPodcasts":"https://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/charts?cc=us&amp;g=1420&amp;name=AudioPodcasts",
           "podcastEpisodes":"https://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/charts?cc=us&amp;g=1420&amp;name=PodcastEpisodes",
           "videoPodcasts":"https://itunes.apple.com/WebObjects/MZStoreServices.woa/ws/charts?cc=us&amp;g=1420&amp;name=VideoPodcasts"
        }
     }
  }
  </code></pre>
  
  <p>I am trying to map this JSON response to a Java object using JAXB and Jackson.  However, the "1420" root element name seems to be causing a problem, as I get the following exception when calling my client:</p>
  
  <pre><code>Unrecognized field "1420" (class foo.bar.ITunesCategoryList), not marked as ignorable
  </code></pre>
  
  <p>My JAXB class looks like this:</p>
  
  <pre><code>@XmlRootElement
  @XmlAccessorType(XmlAccessType.FIELD)
  public class ITunesCategory implements TransferObject {
  
      private static final long serialVersionUID = 3443545925023804457L;
  
      @XmlElement(name = "id")
      @JsonProperty("id")
      private String identifier = null;
  
      @XmlElement
      private String name = null;
  
      @XmlElementWrapper(name = "subgenres")
      private List&lt;ITunesCategory&gt; subcategories = new ArrayList&lt;ITunesCategory&gt;();
  
      ...
  }
  </code></pre>
  
  <p>I've even tried creating a wrapper class since the search could result in more than one category being returned.  It looks like this:</p>
  
  <pre><code>@XmlRootElement
  @XmlAccessorType(XmlAccessType.FIELD)
  public class ITunesCategoryList implements TransferObject {
  
      private static final long serialVersionUID = 3303125979016445238L;
  
      @XmlElement
      private List&lt;ITunesCategory&gt; categories = new ArrayList&lt;ITunesCategory&gt;();
  
      ...
  }
  </code></pre>
  
  <p>However, regardless of which class I specify as my return type, I get the same error because the category identifier is the root element name of the JSON object.</p>
  
  <p>Is there any way to tell JAXB/Jackson/JAX-RS/RESTeasy to ignore the root element name and just map the underlying object to Java?  There is no way for me to know the root element name at develop/compile time, since it corresponds directly to the results returned by the search.  Is there anything that can be done to get around this exception?  Thanks for any help you can give!</p>