title: Correct way of converting nested XML to Java object
body: <p>I am trying to convert the following XML string <strong>(1)</strong> to a Java Object. </p>
  
  <p>I am trying to follow this tutorial : <a href="https://www.javatpoint.com/jaxb-unmarshalling-example" rel="nofollow noreferrer">https://www.javatpoint.com/jaxb-unmarshalling-example</a> but not able to do it correctly. I have 3 class files : AccountObject (2), checkingAccts (3), loanAccts (4). </p>
  
  <p>One point to be noted is that all of the values can be empty/null i.e. checking account list, loan account list and status empty.</p>
  
  <p>What is the acceptable method of converting this XML into the object?</p>
  
  <p>(1)</p>
  
  <pre><code>&lt;AccountObject xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;categories
          xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays"&gt;
          &lt;a:string&gt;category&lt;/a:string&gt;
          &lt;a:string&gt;category&lt;/a:string&gt;
      &lt;/categories&gt;
      &lt;checkingAccts&gt;
          &lt;CheckingAccts&gt;
              &lt;acctNbr&gt;1111&lt;/acctNbr&gt;
              &lt;acctStatus&gt;0&lt;/acctStatus&gt;
              &lt;availBalance&gt;14299.49&lt;/availBalance&gt;
              &lt;balance&gt;14294.49&lt;/balance&gt;
              &lt;dateOpened&gt;2017-09-07&lt;/dateOpened&gt;
              &lt;type&gt;4020&lt;/type&gt;
          &lt;/CheckingAccts&gt;
          &lt;CheckingAccts&gt;
              &lt;acctNbr&gt;2222&lt;/acctNbr&gt;
              &lt;acctStatus&gt;0&lt;/acctStatus&gt;
              &lt;availBalance&gt;470.72&lt;/availBalance&gt;
              &lt;balance&gt;465.72&lt;/balance&gt;
              &lt;dateOpened&gt;2017-09-18&lt;/dateOpened&gt;
              &lt;type&gt;4020&lt;/type&gt;
          &lt;/CheckingAccts&gt;
          &lt;CheckingAccts&gt;
              &lt;acctNbr&gt;4444&lt;/acctNbr&gt;
              &lt;acctStatus&gt;0&lt;/acctStatus&gt;
              &lt;availBalance&gt;5.00&lt;/availBalance&gt;
              &lt;balance&gt;0.00&lt;/balance&gt;
              &lt;dateOpened&gt;2018-04-26&lt;/dateOpened&gt;
              &lt;type&gt;4200&lt;/type&gt;
          &lt;/CheckingAccts&gt;
      &lt;/checkingAccts&gt;
      &lt;loanAccts&gt;
          &lt;LoanAccts&gt;
              &lt;acctNbr&gt;1111&lt;/acctNbr&gt;
              &lt;acctStatus&gt;0&lt;/acctStatus&gt;
              &lt;availBalance&gt;25000.00&lt;/availBalance&gt;
              &lt;balance&gt;1100.03&lt;/balance&gt;
              &lt;dateOpened&gt;2017-10-13&lt;/dateOpened&gt;
              &lt;type&gt;6190&lt;/type&gt;
          &lt;/LoanAccts&gt;
          &lt;LoanAccts&gt;
              &lt;acctNbr&gt;2222&lt;/acctNbr&gt;
              &lt;acctStatus&gt;0&lt;/acctStatus&gt;
              &lt;availBalance&gt;87777.00&lt;/availBalance&gt;
              &lt;balance&gt;0.00&lt;/balance&gt;
              &lt;dateOpened&gt;2018-04-26&lt;/dateOpened&gt;
              &lt;type&gt;6160&lt;/type&gt;
          &lt;/LoanAccts&gt;
      &lt;/loanAccts&gt;
      &lt;statusMessage&gt;THIS IS A TEST MESSAGE&lt;/statusMessage&gt;
  &lt;/AccountObject&gt;
  </code></pre>
  
  <p>(2)</p>
  
  <pre><code>import java.util.List;
  
  import javax.xml.bind.annotation.XmlRootElement;
  
  @XmlRootElement(name = "AccountObject")
  public class AccountObject {
  
      private String statusMessage;
      private List&lt;CheckingAccts&gt; checkingAccounts;
      private List&lt;LoanAccts&gt; loanAccounts;   
  
  
      public List&lt;LoanAccts&gt; getLoanAccounts() {
          return loanAccounts;
      }
  
      public void setLoaanAccounts(List&lt;LoanAccts&gt; loaanAccounts) {
          this.loanAccounts = loaanAccounts;
      }
  
      public String getStatusMessage() {
          return statusMessage;
      }
  
      public void setStatusMessage(String statusMessage) {
          this.statusMessage = statusMessage;
      }
  
  
      public List&lt;CheckingAccts&gt; getCheckingAccounts() {
          return checkingAccounts;
      }
  
      public void setCheckingAccounts(List&lt;CheckingAccts&gt; checkingAccounts) {
          this.checkingAccounts = checkingAccounts;
      }
  
  }
  </code></pre>
  
  <p>(3)</p>
  
  <pre><code>public class CheckingAccts {
  
      protected String acctNbr;
      protected String acctStatus;
      protected String availBalance;
      protected String balance;
      protected String dateOpened;
      protected String type;
  
      public String getAcctNbr() {
          return acctNbr;
      }
  
      public void setAcctNbr(String acctNbr) {
          this.acctNbr = acctNbr;
      }
  
      public String getDateOpened() {
          return dateOpened;
      }
  
      public void setDateOpened(String dateOpened) {
          this.dateOpened = dateOpened;
      }
  
      public String getAcctStatus() {
          return acctStatus;
      }
  
      public void setAcctStatus(String acctStatus) {
          this.acctStatus = acctStatus;
      }
  
      public String getBalance() {
          return balance;
      }
  
      public void setBalance(String balance) {
          this.balance = balance;
      }
  
      public String getAvailBalance() {
          return availBalance;
      }
  
      public void setAvailBalance(String availBalance) {
          this.availBalance = availBalance;
      }
  
      public String getType() {
          return type;
      }
  
      public void setType(String type) {
          this.type = type;
      }
  }
  </code></pre>
  
  <p>(4)</p>
  
  <pre><code>public class LoanAccts {
  
      protected String acctNbr;
      protected String acctStatus;
      protected String availBalance;
      protected String balance;
      protected String dateOpened;
      protected String type;
  
  
      public String getAcctNbr() {
          return acctNbr;
      }
  
      public void setAcctNbr(String acctNbr) {
          this.acctNbr = acctNbr;
      }
  
      public String getAcctStatus() {
          return acctStatus;
      }
  
      public void setAcctStatus(String acctStatus) {
          this.acctStatus = acctStatus;
      }
  
      public String getBalance() {
          return balance;
      }
  
      public void setBalance(String balance) {
          this.balance = balance;
      }
  
      public String getAvailBalance() {
          return availBalance;
      }
  
      public void setAvailBalance(String availBalance) {
          this.availBalance = availBalance;
      }
  
      public String getType() {
          return type;
      }
  
      public void setType(String type) {
          this.type = type;
      }
  
      public String getDateOpened() {
          return dateOpened;
      }
  
      public void setDateOpened(String dateOpened) {
          this.dateOpened = dateOpened;
      }
  </code></pre>
  
  <p>}</p>