title: play: scala Json.format for date
body: <p>I have been having problem with my Json conversion in my <code>play-framework</code> api server for a while and have always been working with tedious workaround. I think that it is a simple and common problem and thus would like to solve it once and for all so that I can have a more maintainable code</p>
  
  <p>I'd need to convert my <code>case class</code> to Json. I have been hard coding a <code>jsonify</code> function that return hardcoded member variable one by one [so tedious but worked]</p>
  
  <p>How do I provide <code>implicit Format</code> for <code>inner case class</code>? I can't override (and don't know which method to override albeit having read the related docs again and again)</p>
  
  <pre><code>case class CaseObject (
    id: String,
    title: String,
    createdDate: java.util.Date // here is the problem
  ) {
  
  }
  
  object CaseObject {
      // is this how to override?
      // val formatter = new SimpleDateFormat("yyyy-MM-dd")
      //  implicit object dateWrites extends Writes[java.util.Date] {
      //    def writes(date: java.util.Date): JsValue = {
      //      JsString(formatter.format(createdDate))
      //    }
      //  }
  
      implicit val CaseObjectFormat = Json.format[CaseObject]
      implicit val CaseObjectReads = Json.reads[CaseObject]
      implicit val CaseObjectWrites = Json.writes[CaseObject]
      implicit val CaseObjectBson = Macros.handler[CaseObject]
  
      // tried circe as well...
      private[this] def fmt = new SimpleDateFormat("yyyy-MM- 
      dd'T'HH:mm:ss.SSSZZ")
      implicit val config: Configuration = Configuration.default
      implicit val dateEncoder: Encoder[Date] = 
          Encoder[String].contramap(fmt.format)
      implicit val dateDecoder: Decoder[Date] = 
          Decoder[String].emapTry(str =&gt; Try(fmt.parse(str)))
  
   }
  </code></pre>
  
  <p>Please help.. I have cracked my head for days for this trivial issue.. Thanks in advance!</p>