0

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

jaksky
  • 3,305
  • 4
  • 35
  • 68
  • First of all, you need to provide an `implicit instance` of `spray.httpx.marshalling.ToResponseMarshaller[ A ]` if you want to marshal some type `A`, which tells marshaller about how to marshal this thing. But here... you are trying to `marshal` a `Future`. This sounds strange, what do you think you will write if your had to kind of `Stringify` a `Future[ Int ]` ?. Example - for `List( 1, 2, 3 )` you can write something like `[ 1, 2, 3 ]`. – sarveshseri Mar 12 '15 at 14:32
  • @SarveshKumarSingh I was following examples from Spray source https://github.com/spray/spray/blob/master/examples/spray-routing/on-spray-can/src/main/scala/spray/examples/DemoService.scala or http://spray.io/documentation/1.2.2/spray-routing/#longer-example – jaksky Mar 12 '15 at 14:51

2 Answers2

0

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

rahilb
  • 726
  • 3
  • 15
0

Change this part, also import scala.concurrent.ExecutionContext.Implicits.global

    respondWithMediaType(MediaTypes.`text/plain`) { ctx=>

    (adImporterService.ask(GetImportStatus)(1 second).mapTo[StatusOfImport]).onComplete {
                case Success(s) => ctx.complete(s)
                case Failure(x)=> ctx.complete(StatusCodes.RequestTimeout)
              }
}
S.Karthik
  • 1,389
  • 9
  • 21