title: Scala type deferring
body: <p>I am using Play framework 2.1 and Scala 2.10.1 and would like to build a general function to construct a JsArray out of a List of custom case class. </p>
  
  <pre><code>private def buildJsArray[T](l: List[T])(result: JsArray): JsArray = {
      l match {
        case List() =&gt; result
        case x::xs =&gt; buildJsArray(xs)(result :+ Json.toJson(x)) // compiling error here!
      }
    }
  </code></pre>
  
  <p>usage:</p>
  
  <pre><code>val applyJsonArray = buildJsArray(List[Apple])(new JsArray())
  </code></pre>
  
  <p>However, a compiling error is thrown:</p>
  
  <blockquote>
  <pre><code>No Json deserializer found for type T. Try to implement an implicit Writes or Format for this 
   type.
  </code></pre>
  </blockquote>
  
  <p>I do have a Json deserializer written for the particular case class(i.e., Apple case class).</p>
  
  <p>How do I defer the compiler to check the type of x in runtime rather than in compile time?</p>
  
  <p>Many Thanks!</p>