title: How to override JAXB @XMLAccessorType(XMLAccessType.FIELD) specified at a Class level with @XMLElement on a getter method for a property?
body: <p>In the example code below, <em>Employee</em> class has been specified with JAXB field level access type. For the property <em>dept</em>, however, the access type has been specified at getter method level with <em>@XMLElement</em> annotation.</p>
  
  <p>During marshalling of <em>Organization</em> class, the following exception is thrown -</p>
  
  <pre><code>com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalAnnotationExceptions
  Class has two properties of the same name "dept"
      this problem is related to the following location:
          at public java.lang.String com.playground.jaxb.Employee.getDept()
      this problem is related to the following location:
          at private java.lang.String com.playground.jaxb.Employee.dept
  </code></pre>
  
  <p>Can you help me understand why this overriding of JAXB accessor type is not working please? Also any solution would be highly appreciated.</p>
  
  <p><strong>Example</strong></p>
  
  <p><strong>Root Element Class</strong></p>
  
  <pre><code>package com.playground.jaxb;
  
  @XMLRootElement(name="organization")
  public class Organization {
  
      @XmlElementWrapper(name = "employees")
      @XmlElement(name = "employee")
      private Set&lt;Employee&gt; employees;
  
      public Organization{}
  
      // Remainder omitted...
  }
  </code></pre>
  
  <p><strong>Employee Class</strong></p>
  
  <pre><code>package com.playground.jaxb;
  
  @XMLAccessorType(XMLAccessType.FIELD)
  public class Employee {
  
      private String name;
  
      private String dept;
  
      @XMLElement(name="department")
      public String getDept() {
          return dept;
      }
  
      public void setDept(String dept) {
          this.dept = dept;
      }
  
      public Employee {}
  
      // Remainder omitted...
  }
  </code></pre>