title: JAXB, Custom bindings, Adapter1.class and Joda-time
body: <p>I have a problem with the way JAXB is generating the bound classes for an XML schema (which, for sake of precision, I cannot modify).
  I want to map a xsd:date type to a Joda-time LocalDate object and, reading <a href="http://blog.bdoughan.com/2011/05/jaxb-and-joda-time-dates-and-times.html" rel="nofollow noreferrer">here</a>, <a href="https://stackoverflow.com/questions/12501581/wsdl-customization-xmlgregoriancalender-to-java-util-date">here</a> and <a href="https://stackoverflow.com/questions/4666988/in-jaxb-how-to-use-xmljavatypeadapters-annotation">here</a>, I created the following DateAdapter class:</p>
  
  <pre><code>public class DateAdapter extends XmlAdapter&lt;String,LocalDate&gt; {
      private static DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyyMMdd");
  
      public LocalDate unmarshal(String v) throws Exception {
          return fmt.parseLocalDate(v);
      }
  
      public String marshal(LocalDate v) throws Exception {
          return v.toString("yyyyMMdd");
      }
  }
  </code></pre>
  
  <p>And I added the following to my global binding file:  </p>
  
  <pre><code>  &lt;jaxb:globalBindings&gt;
          &lt;jaxb:javaType name="org.joda.time.LocalDate" xmlType="xs:date"
              parseMethod="my.classes.adapters.DateAdapter.unmarshal"
              printMethod="my.classes.adapters.DateAdapter.marshal" /&gt;
      &lt;/jaxb:globalBindings&gt;
  </code></pre>
  
  <p>The problem is that, when I try to maven compile my project, it fails with the following error:</p>
  
  <pre><code>[ERROR] \My\Path\MyProject\target\generated-sources\xjc\my\classes\generated\Adapter1.java:[20,59] non-static method unmarshal(java.lang.String) cannot be referenced from a static context
  [ERROR] \My\Path\MyProject\target\generated-sources\xjc\my\classes\generated\Adapter1.java:[24,59] non-static method marshal(org.joda.time.LocalDate) cannot be referenced from a static context
  </code></pre>
  
  <p>...and this is where things get weird.
  JAXB generates a class Adapter1 that contains the following:</p>
  
  <pre><code>public class Adapter1
      extends XmlAdapter&lt;String, LocalDate&gt;
  {
  
  
      public LocalDate unmarshal(String value) {
          return (my.classes.adapters.DateAdapter.unmarshal(value));
      }
  
      public String marshal(LocalDate value) {
          return (my.classes.adapters.DateAdapter.marshal(value));
      }
  
  }
  </code></pre>
  
  <p>....which is the source of the compilation error.</p>
  
  <p>Now, my questions are: </p>
  
  <ul>
  <li>being that my adapter is overriding XmlAdapter, I cannot make the methods static....how do I avoid this?</li>
  <li>Can I avoid the generation of Adapter1.class altogether?? Maybe using package-level annotation XmlJavaTypeAdapters, and if so, how do I do it exactly?? (JAXB generates already a package-info.java of its own....)</li>
  </ul>
  
  <p>Hope I made my situation clear.<br>
  Thanks</p>