我有点困惑为什么下面的代码不起作用:
implicit val connectReads: Reads[ConnectCommand] = (
(JsPath \ "uuid").read[String]
)(ConnectCommand.apply _)
private def generateMessage[T](json: JsValue) = json.validate[T] match {
case s: JsSuccess[T] => s.asOpt
case e: JsError => None
}
该函数将按如下方式调用:
generateMessage[ConnectCommand](json)
我收到以下错误:
Error:(59, 64) No Json deserializer found for type T. Try to implement an implicit Reads or Format for this type.
private def generateMessage[T](json: JsValue) = json.validate[T] match {
^
Error:(59, 64) not enough arguments for method validate: (implicit rds: play.api.libs.json.Reads[T])play.api.libs.json.JsResult[T].
Unspecified value parameter rds.
private def generateMessage[T](json: JsValue) = json.validate[T] match {
^
我对 Scala 泛型相当陌生......有什么办法可以做我想做的事情吗?