title: Mapping XML to an object in Java
body: <p>Suppose I have a class called <em>Test</em>, like this 
  </p>
  
  <pre><code>public class Test {
  
      private String testId;
      private String description;
      private String department;
  
      public Test() {}
  
      public Test(String id,String des,String dpt) {
          this.testId = id;
          this.department = dpt;
          this.description = des;
      }
  
      public String getTestId() {
          return testId;
      }
  
      public void setTestId(String testId) {
          this.testId = testId;
      }
  
      public String getDescription() {
          return description;
      }
  
      public void setDescription(String description) {
          this.description = description;
      }
  
      public String getDepartment() {
          return department;
      }
  
      public void setDepartment(String department) {
          this.department = department;
      }
  
  }
  </code></pre>
  
  <p><br />
  Also an XML string that contains data for an object of the class <em>Test</em>. XML string is
  </p>
  
  <pre><code>&lt;test&gt;
      &lt;testId&gt;1&lt;/testId&gt;
      &lt;description&gt;This is first test&lt;/description&gt;
      &lt;department&gt;surgeon&lt;/department&gt;
  &lt;/test&gt;
  </code></pre>
  
  <p><br />
  Now my task is to parse that XML string and create an object of the class <em>Test</em> and put all of the data contained in this XML into that object. I am using <em>JDOM</em> for XML parsing. I want to know is there any solution through which all of the data that is in the XML format is directly copied into <em>Test</em> object?</p>
  
  <p>Now I am doing this like this: I parse XML string and get data of every node one by one and then call setter method to set data for each field of the <em>Test</em> class object.</p>