title: JAXB / Jackson handling arrays
body: <p>I'm currently writing a Jersey REST interface for a web application. What I want is the ability to be able to serialize a JSON and XML request to the same object however I'm having trouble getting the Jersey (i.e. JAXB / Jackson) to consume the XML and JSON in the format I want.</p>
  
  <p>The XML structure looks like so:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;message&gt;
    &lt;buckets&gt;
      &lt;bucket&gt;
        &lt;channels&gt;
           &lt;channel&gt;Test A&lt;/channel&gt;
           &lt;channel&gt;Test B&lt;/channel&gt;
        &lt;/channels&gt;
        &lt;text&gt;This is sample text&lt;/text&gt;
      &lt;/bucket&gt;
      &lt;bucket&gt;
        &lt;channels&gt;
          ....
        &lt;/channels&gt;
        &lt;text&gt;This is sample text&lt;/text&gt;
      &lt;/bucket&gt;
    &lt;/buckets&gt;
    &lt;userId&gt;10&lt;/userId&gt;
   &lt;/message&gt;
  </code></pre>
  
  <p>The class looks like:</p>
  
  <pre><code>@XmlRootElement(name="message")
  public class MultiMessageRS {
  
      public static class Bucket {
          private List&lt;String&gt; channels;
          private String text;
  
          public Bucket () {}
  
          @XmlElementWrapper(name="channels")
          @XmlElement(name="channel")
          public List&lt;String&gt; getChannels() {
              return channels;
          }
  
          public void setChannels(List&lt;String&gt; channels) {
              this.channels = channels;
          }
          public String getText() {
              return text;
          }
          public void setText(String text) {
              this.text = text;
          }
      }
  
      private List&lt;Bucket&gt; buckets;
  
      private long userId;
  
      public MultiMessageRS () {}
  
      @XmlElementWrapper(name="buckets")
      @XmlElement(name="bucket")
      public List&lt;Bucket&gt; getBuckets() {
          return buckets;
      }
      public void setBuckets(List&lt;Bucket&gt; buckets) {
          this.buckets = buckets;
      }
  
      public long getUserId() {
          return userId;
      }
      public void setUserId(long userId) {
          this.userId = userId;
      }
  }
  </code></pre>
  
  <p>This works fine for the XML however it's unable to consume the JSON in the format I would like. Namely, the issue is that it isn't picking up the channels array. The format is as follows:</p>
  
  <pre><code>{
     "buckets":[
        {
           "bucket":{
              "channels":[
                 "twitter",
                 "mobile"
              ],
              "text":"This is sample text"
           },
           "bucket":{
              "channels":[
                 "email",
                 "voice"
              ],
              "text":"This is sample text"
           }
        }
     ],
     "userId":"10"
  }
  </code></pre>
  
  <p>From it to work correctly with the JSON, I would have to do something like adding a 'channel' array under 'channels' which is pretty dodgy. How will I be able to handle this situation?</p>