我一直在尝试编组一堆地图,但我得到了错误。以下是定义:
import spray.httpx.SprayJsonSupport._
import spray.json.DefaultJsonProtocol._
import scala.collection.JavaConverters._
case class SchemaMap( schemaMap: scala.collection.immutable.Map[String, Integer] ) /** FIRST ERROR IS HERE!! **/
case class Profile( counts: scala.collection.immutable.Map[String, SchemaMap] )
case class Profiles( profiles: scala.collection.immutable.Seq[Profile] )
object Profiles {
implicit val schemaMapMarshall = jsonFormat1(SchemaMap.apply)
implicit val profileMarshall = jsonFormat1(Profile.apply)
implicit val profilesMarshall = jsonFormat1(Profiles.apply)
def convertAProfileToScala(javaProfile: edu.illinois.cs.cogcomp.profilerNew.model.Profile): Profile = {
val out = javaProfile.getAllSchema.asScala.map{item =>
(item._1, SchemaMap(item._2.asScala.toMap))
}.toMap
Profile(out)
}
def convert[Profiles](sq: collection.mutable.Seq[Profiles]): collection.immutable.Seq[Profiles] =
collection.immutable.Seq[Profiles](sq:_*)
def convertProfilesToScala(javaProfiles: java.util.List[edu.illinois.cs.cogcomp.profilerNew.model.Profile]): Profiles = {
val a: collection.mutable.Seq[Profile] = javaProfiles.asScala.map{ convertAProfileToScala }
val immutableSeq = collection.immutable.Seq[Profile](a:_*)
Profiles(immutableSeq)
}
}
这是错误:
Error:(16, 47) could not find implicit value for evidence parameter of type spray.json.DefaultJsonProtocol.JF[scala.collection.immutable.Map[String,Integer]]
implicit val schemaMapMarshall = jsonFormat1(SchemaMap.apply)
^
Error:(16, 47) not enough arguments for method jsonFormat1: (implicit evidence$1: spray.json.DefaultJsonProtocol.JF[scala.collection.immutable.Map[String,Integer]], implicit evidence$2: ClassManifest[org.allenai.example.webapp.SchemaMap])spray.json.RootJsonFormat[org.allenai.example.webapp.SchemaMap].
Unspecified value parameters evidence$1, evidence$2.
implicit val schemaMapMarshall = jsonFormat1(SchemaMap.apply)
^
Error:(17, 45) could not find implicit value for evidence parameter of type spray.json.DefaultJsonProtocol.JF[scala.collection.immutable.Map[String,org.allenai.example.webapp.SchemaMap]]
implicit val profileMarshall = jsonFormat1(Profile.apply)
^
Error:(17, 45) not enough arguments for method jsonFormat1: (implicit evidence$1: spray.json.DefaultJsonProtocol.JF[scala.collection.immutable.Map[String,org.allenai.example.webapp.SchemaMap]], implicit evidence$2: ClassManifest[org.allenai.example.webapp.Profile])spray.json.RootJsonFormat[org.allenai.example.webapp.Profile].
Unspecified value parameters evidence$1, evidence$2.
implicit val profileMarshall = jsonFormat1(Profile.apply)
^
Error:(18, 46) could not find implicit value for evidence parameter of type spray.json.DefaultJsonProtocol.JF[scala.collection.immutable.Seq[org.allenai.example.webapp.Profile]]
implicit val profilesMarshall = jsonFormat1(Profiles.apply)
^
Error:(18, 46) not enough arguments for method jsonFormat1: (implicit evidence$1: spray.json.DefaultJsonProtocol.JF[scala.collection.immutable.Seq[org.allenai.example.webapp.Profile]], implicit evidence$2: ClassManifest[org.allenai.example.webapp.Profiles])spray.json.RootJsonFormat[org.allenai.example.webapp.Profiles].
Unspecified value parameters evidence$1, evidence$2.
implicit val profilesMarshall = jsonFormat1(Profiles.apply)
^
注意:这里有一个类似的帖子,但这里的答案没有帮助。如您所见,我已经在其答案中建议了导入并拥有所有变量immutable
。