Маршалирование карт с помощью спрея

Я пытался упорядочить несколько карт, но получаю ошибку. Вот определения:

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.


person Daniel    schedule 01.07.2015    source источник


Ответы (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].

person lmm    schedule 01.07.2015