title: How to Customise a Getter and Setter method for JAXB Bindings
body: <p>We have 5 xsd files, first.xsd, second.xsd, third.xsd and so on.</p>
  
  <p>We want to use Calendar for dateTime types that are defined in every xsd files, except for first.xsd. </p>
  
  <pre><code>&lt;jaxb:globalBindings&gt;
      &lt;jaxb:javaType name="java.util.Calendar" xmlType="xsd:dateTime" parseMethod="javax.xml.bind.DatatypeConverter.parseDateTime" printMethod="javax.xml.bind.DatatypeConverter.printDateTime"/&gt;
      &lt;jaxb:serializable/&gt;
  &lt;/jaxb:globalBindings&gt;
  </code></pre>
  
  <p>Our intention to use this entry was to tell JAXB to generate Calendar whenever we are using dateTime in our xsd files. However, we want to use XMLGregorianCalendar for the java types that we define in first.xsd:</p>
  
  <pre><code> ...
   &lt;xsd:simpleType name="myDateType"&gt;
      &lt;xsd:restriction base="xsd:dateTime"&gt;
      &lt;/xsd:restriction&gt;
   &lt;/xsd:simpleType&gt;
   ...
  </code></pre>
  
  <p>To achieve this, we add this entry in our jaxbBinding file:</p>
  
  <pre><code>&lt;jaxb:bindings schemaLocation="first.xsd"&gt;
  
      &lt;jaxb:bindings node="xsd:simpleType[@name='myDateType']"&gt;
          &lt;jaxb:class name="XMLGregorianCalendar" implClass="javax.xml.datatype.XMLGregorianCalendar" /&gt;                  
          &lt;jaxb:schemaBindings&gt;
              &lt;jaxb:package name="javax.xml.datatype"/&gt;
          &lt;/jaxb:schemaBindings&gt;
      &lt;/jaxb:bindings&gt;
  
  
    &lt;/jaxb:bindings&gt;
  </code></pre>
  
  <p>We find that the generated java file has a peculiar getter setter method:</p>
  
  <pre><code>package com.time;
  
  public class MyClass{
  
     @XmlElement(name = "MyDate", required = true)
     protected XMLGregorianCalendar sentenceDate;
  
  
     public com.time.XMLGregorianCalendar getMyDate() {
      return myDateType;
     } 
  
  
     public void setMyDate(com.time.XMLGregorianCalendar value) {
      return this.myDateType = (com.time.XMLGregorianCalendar)value;
     }
  </code></pre>
  
  <p>We expect that JAXB will create a getter setter method that set and return a com.time.XMLGregorianCalendar. However it does not.</p>
  
  <p>Does anyone know what should I use to tell JAXB to use javax.xml.datatype.XMLGregorianCalendar for the getter and setter method in my class ?</p>
  
  <p>Thank you.</p>