0

一連のマップをマーシャリングしようとしていますが、エラーが発生します。定義は次のとおりです。

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

4

1 に答える 1

1

一度に 1 つのエラー。ここでの問題は、マップが を使用してIntegerおり、Spray がマップ方法を認識していないことです。使用Intすると動作します:

scala> case class SchemaMap( schemaMap: scala.collection.immutable.Map[String, Integer] )
defined class SchemaMap

scala> val schemaMapMarshall = jsonFormat1(SchemaMap.apply)
<console>:12: error: could not find implicit value for evidence parameter of type spray.json.DefaultJsonProtocol.JF[scala.collection.immutable.Map[String,Integer]]
scala> case class SchemaMap( schemaMap: scala.collection.immutable.Map[String, Int])
defined class SchemaMap

scala> val schemaMapMarshall = jsonFormat1(SchemaMap.apply)
schemaMapMarshall: spray.json.RootJsonFormat[SchemaMap] = spray.json.ProductFormatsInstances$$anon$1@53e166ad

または、独自の を定義することもできますJsonFormat[Integer]

于 2015-07-01T08:55:22.950 に答える