title: How to Instantiate and store values in List<JAXBElement<?>>
body: <p>I have generated java client from a Wsdl. I am stuck at following code where I have to set some setters values in following <code>List&lt;JAXBElement&lt;?&gt;&gt;</code>  </p>
  
  <pre><code>public class SampleVerificationDomain
         extends BaseDomain
      {
  
         protected List&lt;JAXBElement&lt;?&gt;&gt; rest;
  
         /**
           * Gets the rest of the content model. 
           *  
           * &lt;p&gt;
           * This accessor method returns a reference to the live list,
           * not a snapshot. Therefore any modification you make to the
           * returned list will be present inside the JAXB object.
           * This is why there is not a &lt;CODE&gt;set&lt;/CODE&gt; method for the rest property.
           * 
           * &lt;p&gt;
           * For example, to add a new item, do as follows:
           * &lt;pre&gt;
           *    getRest().add(newItem);
           * &lt;/pre&gt;
           *  
           * &lt;p&gt;
           * Objects of the following type(s) are allowed in the list
           * {@link JAXBElement }{@code &lt;}{@link String }{@code &gt;}
           * {@link JAXBElement }{@code &lt;}{@link String }{@code &gt;}
           * {@link JAXBElement }{@code &lt;}{@link String }{@code &gt;}
           * {@link JAXBElement }{@code &lt;}{@link String }{@code &gt;}
           * {@link JAXBElement }{@code &lt;}{@link DummyVerification }{@code &gt;}
           * {@link JAXBElement }{@code &lt;}{@link String }{@code &gt;}
           *
           */
          public List&lt;JAXBElement&lt;?&gt;&gt; getRest() {
              if (rest == null) {
                  rest = new ArrayList&lt;JAXBElement&lt;?&gt;&gt;();
              }
              return this.rest;
          }
  </code></pre>
  
  <p>I know how to store values if it is <code>List&lt;Class&gt;</code> or <code>List&lt;String&gt;</code> etc,
  but how can I store value in a <code>JAXBElement</code> of type <code>&lt;?&gt;</code> and then store it in a List ?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>With help of this [<a href="https://stackoverflow.com/a/19548424/9811170]">https://stackoverflow.com/a/19548424/9811170]</a>, I have found ObjectFacotry class, which contains create functions of the values that needs to be set.</p>
  
  <pre><code>JAXBElement&lt;?&gt; jasbElem = null;     
  jasbElem =  objectFactory.createSampleVerificationDomainCNIC("2392923");
  jasbElem =  objectFactory.createSampleVerificationDomainMSISDN("xxxxxxx");
  jasbElem =  objectFactory.createSampleVerificationDomainMsg("some message");
  jasbElem =  objectFactory.createSampleVerificationDomainUserName("apiusername");
  jasbElem =  objectFactory.createSampleVerificationDomainPassword("testpass");
  
  
  SampleTestVerificationDomain.getRest().add(jasbElem);
  </code></pre>
  
  <p>But the above code only sets the last value in the JAXBElement.
  Any help on how to store all the values in JAXBElement ?</p>