title: Scala classOf for type parameter, revisited
body: <p>Following on from:</p>
  
  <p><a href="https://stackoverflow.com/questions/6200253/scala-classof-for-type-parameter">Scala classOf for type parameter</a></p>
  
  <p>I've tried implementing it but seem to get some weird generics problem, actually I've muddled my way through a couple of them now, but this is as close to correct I can get it...</p>
  
  <p>I'm using the Scala - Jackson JSON bindings (excellent lib by the way, much easier than SJson)</p>
  
  <pre><code>def genparseResult[T: ClassManifest](t: T,s:String):Either[Tuple2[JsonParseException,String],T] = {
    try{
      val res = jsonSerializer.readValue(s,  classManifest[T].erasure)
      Right(res)
    }
    catch{
      case jpe:JsonParseException =&gt; Left((jpe,s))
    }
  }
  </code></pre>
  
  <p>Anyhow, the code above is generating the following compile error: </p>
  
  <blockquote>
    <p>type mismatch;  found   : res.type (with underlying type Any)  required: T    </p>
  </blockquote>
  
  <p>I'm confused as hell. Should the code above be able to work?</p>
  
  <p><strong>Update</strong>
  <em>following input from tenshi, I post the completed class</em></p>
  
  <pre><code>import com.fasterxml.jackson.core.JsonParseException
  object DatasiftJsonMapper {
    import java.util.Date
    import com.fasterxml.jackson.databind.{ Module, ObjectMapper }
    import com.fasterxml.jackson.module.scala.DefaultScalaModule
  
    val jsonSerializer = {
      val m = new ObjectMapper()
      m.registerModule(DefaultScalaModule)
      m
    }
  
    def parseDSResult(s: String): Either[Tuple2[JsonParseException, String], DatasiftResult] = {
      genparseResult(classOf[DatasiftResult], s)
    }
  
    def parseQRegRequest(s: String): Either[Tuple2[JsonParseException, String], QRegRequest] = {
      genparseResult(classOf[QRegRequest], s)
    }
  
    def genparseResult[T: ClassManifest](t: Class[T], s: String): Either[Tuple2[JsonParseException, String], T] = {
      try {
        val res = jsonSerializer.readValue(s, classManifest[T].erasure).asInstanceOf[T]
        Right(res)
      } catch {
        case jpe: JsonParseException =&gt; Left((jpe, s))
      }
    }
  }
  </code></pre>