title: Custom convert XMLGregorianCalendar to Date with BeanUtils
body: <p>I’m trying to register a custom converter for XMLGregorianCalendars to do the conversión from POJO received by WS (with XMLGregorianCalendar fields) to my model (Date objects).</p>
  
  <p>I tried to register to process properties with XMLGregorianCalendar.class, but the it seems to be an anonymous class and in executing time is detected as XMLGregorianCalendarImpl.class, which doesn’t cause the triggering of my custom converter.</p>
  
  <p>How can I do this conversion? I can register to XMLGregorianCalendarImpl.class because it is not a “visible” class…</p>
  
  <p>Here it's my code:</p>
  
  <pre><code>[…]
  ConvertUtils.register(new XMLGregorianCalendarConverter(), XMLGregorianCalendar.class);
  BeanUtils.copyProperties(result, original);
  […] //”result” is a object from my model with Date properties and “original” a pojo with properties with the same name but with XMLGregorianCalendar.
  </code></pre>
  
  <p>XMLGregorianCalendarConverter.class:</p>
  
  <pre><code>import javax.xml.datatype.XMLGregorianCalendar;
  import org.apache.commons.beanutils.converters.DateConverter;
  
  public class XMLGregorianCalendarConverter implements org.apache.commons.beanutils.Converter{
  
         private DateConverter dateConverter = new org.apache.commons.beanutils.converters.DateConverter();
  
         @SuppressWarnings("unchecked")
         @Override
         public &lt;T&gt; T convert(Class&lt;T&gt; type, Object value) {
               if(value == null || value.toString().length() &lt; 1)
                      return null;
  
               if(type.toString().contains("XMLGregorianCalendar")){
                      XMLGregorianCalendar xmldate = (XMLGregorianCalendar) value;
                      return (T) xmldate.toGregorianCalendar().getTime();
               }else{
                      return dateConverter.convert(type, value);
               }
         }
  
  }
  </code></pre>
  
  <p>Thanks!</p>