scalaakkasprayspray-dsl

spray-routing - akka ask with Marshaller


I am trying to complete a service in spray.io following examples from original documentation and I am stuck on error message:

could not find implicit value for parameter marshaller: spray.httpx.marshalling.ToResponseMarshaller[scala.concurrent.Future[AdImporterServiceActor.StatusOfImport]]


val adServiceRoute: Route = {
    path("service" / "import" / "status") {
      get {
        respondWithMediaType(`text/plain`) {
          complete {
            adImporterService.ask(GetImportStatus)(1 second).mapTo[StatusOfImport]
          }
        }
      }
    }
  }

  implicit val importStatusMarshaller: Marshaller[StatusOfImport] =
    Marshaller.of[StatusOfImport](ContentTypes.`text/plain`) { (value, contentType, ctx) =>
      val string = "Hello marshalled status"
      ctx.marshalTo(HttpEntity(contentType, string))
    }

where

  case class StatusOfImport(statuses: Map[String, ImportStatus], activeRequests:Set[Import])

  case class ImportStatusUpdate(adId: String, statusUpdate: ImportStatus)

I am not sure whtat I am missing here. Can somebody more experienced give a hint?

Thx


Solution

  • I think you need an implicit ExecutionContext in scope, to provide the Future marshalling ability.