title: Serialize Date in a JSON REST web service as ISO-8601 string
body: <p>I have a JAX-RS application using JBoss AS 7.1, and I POST/GET JSON and XML objects which include Dates (java.util.Date):</p>
  
  <pre><code>@XmlRootElement
  @XmlAccessorType(XmlAccessField.FIELD)
  public class MyObject implements Serializable
  {
      @XmlSchemaType(name = "dateTime")
      private Date date;
      ...
  }
  </code></pre>
  
  <p>When I use @Produce("application/xml") on the get method, the objets are serialized as XML and the dates are converted into ISO-8601 strings (e.g. "2012-12-10T14:50:12.123+02:00").</p>
  
  <p>However, if I use @Produce("application/json") on the get method, the dates in the JSON objects are timestamps (e.g. "1355147452530") instead of ISO-8601 strings.</p>
  
  <p>How can I do to configure the JAX-RS implementation (RESTEasy) to serialize dates in JSON format as ISO-8601 strings instead of timestamps ?</p>
  
  <p>Thank you for your answers.</p>
  
  <p>Note: I also tried to use a custom JAX-RS provider to do the JSON serialization for Dates</p>
  
  <pre><code>@Provider
  @Produces(MediaType.APPLICATION_JSON)
  public class CustomJsonDateProvider implements MessageBodyWriter&lt;Date&gt;
  {
      ...
  }
  </code></pre>
  
  <p>This provider seems to be registered by RESTeasy on JBoss startup:</p>
  
  <pre><code>[org.jboss.jaxrs] Adding JAX-RS provider classes: package.CustomJsonDateProvider
  ...
  [org.jboss.resteasy.cdi.CdiInjectorFactory] No CDI beans found for class package.CustomJsonDateProvider. Using default ConstructorInjector.
  </code></pre>
  
  <p>but it is never used !</p>