I have some code like this:
class ReflectiveJsonFormat[T:TypeTag] extends JsonFormat[T] {
def write(x: T) : JsValue = {
val t = typeOf[T]
val getters
Well scala does support multiple context bounds if that is what you are after:
class ReflectiveJsonFormat[T:TypeTag:ClassTag]
The library doesn't provide a built-in method that directly converts a TypeTag
to a ClassTag
, but you can write one:
import reflect.runtime.universe._
import reflect.ClassTag
def typeToClassTag[T: TypeTag]: ClassTag[T] = {
ClassTag[T]( typeTag[T].mirror.runtimeClass( typeTag[T].tpe ) )
}
Then in your method just add before the implicit ClassTag
is needed:
implicit val c = typeToClassTag[T]