title: JAXB Unmarshal a list of objects
body: <p>I have the following XML that I am trying to unmarshal:</p>
  
  <pre><code>&lt;ListOfYear&gt;
      &lt;Requests/&gt;
      &lt;Payload&gt;
          &lt;Year&gt;
              &lt;Value&gt;2013&lt;/Value&gt;
          &lt;/Year&gt;
          &lt;Year&gt;
              &lt;Value&gt;2012&lt;/Value&gt;
          &lt;/Year&gt;
          &lt;Year&gt;
              &lt;Value&gt;2011&lt;/Value&gt;
          &lt;/Year&gt;
          &lt;Year&gt;
              &lt;Value&gt;2010&lt;/Value&gt;
          &lt;/Year&gt;
          &lt;Year&gt;
              &lt;Value&gt;2009&lt;/Value&gt;
          &lt;/Year&gt;
          &lt;Year&gt;
              &lt;Value&gt;2008&lt;/Value&gt;
          &lt;/Year&gt;
      &lt;/Payload&gt;
  &lt;/ListOfYear&gt;
  </code></pre>
  
  <p>My java class looks like this:</p>
  
  <pre><code>@XmlRootElement(name = "ListOfYear")
  public class YearOutput {
  
      @XmlElementWrapper(name = "Payload")
      @XmlElement(name = "Year")
      private ArrayList&lt;Year&gt; Payload;
  
      public ArrayList&lt;Year&gt; getPayload() {
          return Payload;
      }
  
      public void setPayload(ArrayList&lt;Year&gt; payload) {
          Payload = payload;
      }
  }
  </code></pre>
  
  <p>Payload should contain a list of year objects:</p>
  
  <pre><code>@XmlRootElement(name = "Year")
  @XmlAccessorType(XmlAccessType.FIELD).
  public class Year {
  
      @XmlElement(name = "Value")
      int Value;
  
      public int getValue() {
          return Value;
      }
  
      public void setValue(int value) {
          Value = value;
      }
  }
  </code></pre>
  
  <p>I am unmarshaling the XML with the following code:</p>
  
  <pre><code>String r = response.getEntity(String.class);
  JAXBContext jaxbContext = JAXBContext.newInstance(YearOutput.class);
  Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
  
  YearOutput output = (YearOutput) unmarshaller.unmarshal(new StringReader(r));
  </code></pre>
  
  <p>I get an output object back just fine, the payload object is always null. I have tried several different approaches with my XML annotation and have not been able to get anything to work. Any help would be much appreciated.</p>
  
  <p><strong>EDIT</strong>
  I thought the name space was inconsequential so I didn't post that part of the code. But @Blaise Doughan suggested I marshal my model and it appears my  namespace may be causing an issue...</p>
  
  <p>Here is the full XML that I need:</p>
  
  <pre><code>&lt;ListOfYear xmlns="http://something.com/"&gt;
      &lt;Requests/&gt;
      &lt;Payload&gt;
          &lt;Year&gt;
              &lt;Value&gt;2013&lt;/Value&gt;
          &lt;/Year&gt;
          &lt;Year&gt;
              &lt;Value&gt;2012&lt;/Value&gt;
          &lt;/Year&gt;
          &lt;Year&gt;
              &lt;Value&gt;2011&lt;/Value&gt;
          &lt;/Year&gt;
          &lt;Year&gt;
              &lt;Value&gt;2010&lt;/Value&gt;
          &lt;/Year&gt;
          &lt;Year&gt;
              &lt;Value&gt;2009&lt;/Value&gt;
          &lt;/Year&gt;
          &lt;Year&gt;
              &lt;Value&gt;2008&lt;/Value&gt;
          &lt;/Year&gt;
      &lt;/Payload&gt;
  &lt;/ListOfYear&gt;
  </code></pre>
  
  <p>Here is my full model:</p>
  
  <pre><code>@XmlRootElement(name = "ListOfYear", namespace = "http://something.com/")
  public class YearOutput {
  
      @XmlElementWrapper(name = "Payload")
      @XmlElement(name = "Year")
      private ArrayList&lt;Year&gt; Payload;
  
      public ArrayList&lt;Year&gt; getPayload() {
          return Payload;
      }
  
      public void setPayload(ArrayList&lt;Year&gt; payload) {
          Payload = payload;
      }
  }
  </code></pre>
  
  <p>Now when I marshal my model I am getting: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ns2:ListOfYear xmlns:ns2="https://something.com/"&gt;
      &lt;Payload&gt;
          &lt;Year&gt;
              &lt;Value&gt;2008&lt;/Value&gt;
          &lt;/Year&gt;
      &lt;/Payload&gt;
  &lt;/ns2:ListOfYear&gt;
  </code></pre>
  
  <p>So what am I doing wrong with my namespace?</p>
  
  <p><strong>EDIT</strong>
  After adding package-info.java everything works perfect!</p>
  
  <pre><code>@XmlSchema(
          namespace = "https://something.com/",
          elementFormDefault = XmlNsForm.QUALIFIED)
  package example;
  
  import javax.xml.bind.annotation.XmlNsForm;
  import javax.xml.bind.annotation.XmlSchema;
  </code></pre>