title: Register a new Date Converter Auditable in Spring Data MongoDB for ZonedDateTime
body: <p>I want my auditable (<code>@CreatedDate</code> and <code>@LastModifiedDate</code>) MongoDB document to work with <code>ZonedDateTime</code> fields.</p>
  
  <p>Apparently this type is not supported by Spring Data (have a look at <code>org.springframework.data.auditing.AnnotationAuditingMetadata</code>).</p>
  
  <p>Framework version: <strong>Spring Boot 2.0.0</strong> and <strong>Spring Data MongoDB 2.0.0</strong></p>
  
  <h3>Spring Data auditing error:</h3>
  
  <pre><code>java.lang.IllegalArgumentException: Invalid date type for member &lt;MEMBER NAME&gt;!
  Supported types are [org.joda.time.DateTime, org.joda.time.LocalDateTime, java.util.Date, java.lang.Long, long].
  </code></pre>
  
  <h3>Mongo configuration:</h3>
  
  <pre class="lang-java prettyprint-override"><code>@Configuration
  @EnableMongoAuditing
  public class MongoConfiguration {
  
  }
  </code></pre>
  
  <h3>The auditable entity:</h3>
  
  <pre class="lang-java prettyprint-override"><code>public abstract class BaseDocument {
  
      @CreatedDate
      private ZonedDateTime createdDate;
  
      @LastModifiedDate
      private ZonedDateTime lastModifiedDate;
  
  }
  </code></pre>
  
  <h2>Things I tried</h2>
  
  <p>I also tried creating a custom converter for <code>ZonedDateTime</code>, but it is not considered by Spring Data. The class <code>DateConvertingAuditableBeanWrapper</code> has a <code>ConversionService</code> which is configured in the constructor method with <code>JodaTimeConverters</code>, <code>Jsr310Converters</code> and <code>ThreeTenBackPortConverters</code>.</p>
  
  <h3>Custom converter:</h3>
  
  <pre class="lang-java prettyprint-override"><code>@Component
  public class LocalDateTimeToZonedDateTimeConverter implements Converter&lt;LocalDateTime, ZonedDateTime&gt; {
  
      @Override
      public ZonedDateTime convert(LocalDateTime source) {
          return source.atZone(ZoneId.systemDefault());
      }
  
  }
  </code></pre>
  
  <h3>Spring Data DateConvertingAuditableBeanWrapper:</h3>
  
  <pre class="lang-java prettyprint-override"><code>class DefaultAuditableBeanWrapperFactory implements AuditableBeanWrapperFactory {
  
      abstract static class DateConvertingAuditableBeanWrapper implements AuditableBeanWrapper {
  
          private final ConversionService conversionService;
  
      }
  }
  </code></pre>
  
  <p>Is it possible to audit <code>ZonedDateTime</code> fields?</p>
  
  <p>How can I register a converter?</p>