J'ai un code qui ressemble à ça.Comment sérialiser des objets de/vers json en spray avec defaultFormats?
import akka.actor.{Props, ActorRef, Actor}
import akka.util.Timeout
import org.json4s.DefaultFormats
import spray.routing.HttpService
import spray.httpx.Json4sSupport
import scala.concurrent.Await
import scala.concurrent.duration._
import akka.pattern.ask
/**
* Created by mihaildoronin on 06.10.15.
*/
class ProcessesService() extends Actor with HttpService {
def actorRefFactory = context
def receive = runRoute(route)
val systemActor = context.actorOf(Props[SystemActor])
implicit val json4sFormats = DefaultFormats
implicit val timeout = Timeout(5 seconds)
val route = path("processes") {
get {
parameters('fromId.as[Int], 'count.as[Int]).as(GetProcessesCommand) { command =>
complete {
val response = Await.result(systemActor ? command, timeout.duration).asInstanceOf[CursoredResponse]
response
}
}
} ~
post {
entity(as[RegisterProcessCommand]) { command =>
complete {
val result = Await.result(systemActor ? command, timeout.duration).asInstanceOf[Long]
}
}
}
} ~
pathPrefix("processes"/IntNumber) { id =>
complete {
val process = Await.result(systemActor ? GetProcessCommand(id), timeout.duration).asInstanceOf[Process]
process
}
}
}
Il me donne des erreurs comme ça
Error:(28, 11) type mismatch;
found : CursoredResponse
required: spray.httpx.marshalling.ToResponseMarshallable
response
^
Mais dans ce tutorial un code similaire semble fonctionner. J'ai surchargé json4sFormats et je les ai implicites, j'utilise des classes de cas, qu'est-ce qui me manque ici? Je suis nouveau pour scala et spray, donc ce n'est pas clair pour moi.