title: using custom jaxb bindings to get xs:datetime to Joda time but getting XMLGregorianCalender
body: <p>Java 1.7
  Spring 3.1.1 with Spring-WS 2.1.1
  Joda
  Hibernate 3.6
  MySQL 5.0.57
  Maven 3
  Tomcat 7
  Eclipse 3.7 </p>
  
  <p>Have got the web service deployed and the web client deployed and the web
  service and web client talking to each other. </p>
  
  <p>But just like in a vintage video game, slaying a batch of dragons just spawns
  another batch of dragons.</p>
  
  <p>Now it's the whole Joda Datetime xs:dateTime jaxb binding thingy thats spewing fire at me.</p>
  
  <p>Googling turns up lots of solutions which I have tried to follow. </p>
  
  <p>a representative entity </p>
  
  <pre><code>@Entity
  @Table(name="form_templates", catalog="mycomp")
  @XmlRootElement
  @XmlAccessorType(XmlAccessType.FIELD)
  public class FormTemplate implements java.io.Serializable
  {
      private static final long serialVersionUID = 8533964268513480152L;
      ....
  
      @Column(name="revision_datetime")
      @Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
      @XmlElement(name="revisionTimestamp")
      @XmlJavaTypeAdapter(JodaDateTimeAdapter.class)
      @XmlSchemaType(name="dateTime")
      DateTime revisionTimestamp;
      .... 
  }
  </code></pre>
  
  <p>JodaDateTimeAdapter</p>
  
  <pre><code>@XmlTransient
  public class JodaDateTimeAdapter extends XmlAdapter&lt;String, DateTime&gt;
  {
      private static final DateTimeFormatter XML_DATE_FORMAT =      ISODateTimeFormat.dateTimeNoMillis();  
      private static final DateTimeFormatter XML_DATE_TIME_FORMAT = ISODateTimeFormat.localDateOptionalTimeParser();  
      private static final DateTimeFormatter DATE_PATTERN =         DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS");  
  
      public DateTime unmarshal(String dateStr) throws Exception  
      {   //parsing from schema to java class  
          DateTime result = DATE_PATTERN.parseDateTime(dateStr);  
          return result;  
      }  
  
      public String marshal(DateTime dateTime) throws Exception  
      {   //printing from java class to schema  
          String result   = DATE_PATTERN.print(dateTime);  
          return result;  
      }  
  }
  </code></pre>
  
  <p>relavent part of pom</p>
  
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
      &lt;artifactId&gt;cxf-java2ws-plugin&lt;/artifactId&gt;
      &lt;version&gt;${cxfVersion}&lt;/version&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
              &lt;artifactId&gt;cxf-rt-frontend-jaxws&lt;/artifactId&gt;
              &lt;version&gt;${cxfVersion}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
              &lt;artifactId&gt;cxf-rt-frontend-simple&lt;/artifactId&gt;
              &lt;version&gt;${cxfVersion}&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;id&gt;process-classes&lt;/id&gt;
              &lt;phase&gt;process-classes&lt;/phase&gt;
              &lt;configuration&gt;
                  &lt;outputFile&gt;src/main/webapp/WEB-INF/wsdl/FormsService.wsdl&lt;/outputFile&gt;
                  &lt;className&gt;com.mycomp.forms.web.endpoint.FormsEndpoint&lt;/className&gt;
                  &lt;genWsdl&gt;true&lt;/genWsdl&gt;
                  &lt;verbose&gt;true&lt;/verbose&gt;
              &lt;/configuration&gt;
              &lt;goals&gt;
                  &lt;goal&gt;java2ws&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  </code></pre>
  
  <p>So the web service compiles and deploys successfully. I look in the wsdl and see</p>
  
  <pre><code>...
  &lt;xs:complexType name="formTemplate"&gt;
      &lt;xs:sequence&gt;
        ...
        &lt;xs:element minOccurs="0" name="revisionTimestamp" type="xs:dateTime"/&gt;
        ...
  </code></pre>
  
  <p>so it seems I'm headed in the right direction. With the web service deployed I turn my attention
  to the web client</p>
  
  <p>I compile the web client with this relavent pom snippet</p>
  
  <pre><code>  ...
    &lt;plugin&gt;
      &lt;groupId&gt;org.apache.cxf&lt;/groupId&gt;
      &lt;artifactId&gt;cxf-codegen-plugin&lt;/artifactId&gt;
      &lt;version&gt;${cxfVersion}&lt;/version&gt;
      &lt;executions&gt;
        &lt;execution&gt;
          &lt;id&gt;generate-sources&lt;/id&gt;
          &lt;phase&gt;generate-sources&lt;/phase&gt;
          &lt;configuration&gt;
            &lt;sourceRoot&gt;${project.build.directory}/generated_sources&lt;/sourceRoot&gt;
            &lt;wsdlOptions&gt;
              &lt;wsdlOption&gt;
                &lt;wsdl&gt;http://localhost:8080/dept_forms_webservice/formsService?wsdl&lt;/wsdl&gt;
                &lt;bindingFiles&gt;
                  &lt;bindingFile&gt;${basedir}/src/main/resources/jaxb-custom-bindings.xml&lt;/bindingFile&gt;
                &lt;/bindingFiles&gt;
              &lt;/wsdlOption&gt;
            &lt;/wsdlOptions&gt;
          &lt;/configuration&gt;
          &lt;goals&gt;
            &lt;goal&gt;wsdl2java&lt;/goal&gt;
          &lt;/goals&gt;
        &lt;/execution&gt;
      &lt;/executions&gt;
    &lt;/plugin&gt;     
    ...
  </code></pre>
  
  <p>and jaxb-custom-bindings.xml located in /src/java/resources</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jaxws:bindings wsdlLocation="http://localhost:8080/dept_forms_webservice/formsService?wsdl"
            xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:jxb="http://java.sun.com/xml/ns/jaxb"&gt;
    &lt;jaxws:bindings&gt;
      &lt;jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
          &lt;jxb:javaType name="org.joda.time.DateTime" xmlType="xs:dateTime"
                        parseMethod="com.mycomp.forms.util.JodaDateTimeAdapter.unmarshall"
                        printMethod="com.mycomp.forms.util.JodaDateTimeAdapter.marshall"/&gt;
      &lt;/jxb:globalBindings&gt;
    &lt;/jaxws:bindings&gt;
  &lt;/jaxws:bindings&gt;
  </code></pre>
  
  <p>and everything compiles, sources get generated, web client deploys successfully</p>
  
  <p>BUT</p>
  
  <p>looking in the generated FormTemplate entity I see</p>
  
  <pre><code>import javax.xml.bind.annotation.XmlAccessType;
  import javax.xml.bind.annotation.XmlAccessorType;
  import javax.xml.bind.annotation.XmlSchemaType;
  import javax.xml.bind.annotation.XmlType;
  import javax.xml.datatype.XMLGregorianCalendar;  // &lt;---- should be joda datetime here
  
  public class FormTemplate
  {
      ...
      @XmlSchemaType(name = "dateTime")
      protected XMLGregorianCalendar revisionTimestamp;   // &lt;-- should be joda datetime here
  ...
  </code></pre>
  
  <p>So I've clearly missed some microscopic piece of configuration minutae and would be ever so
  grateful if someone would point out what is wrong and how to right it.</p>
  
  <p>TIA,</p>
  
  <p>Still-learning Steve    </p>