Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

spray Marshaller for futures not in implicit scope after upgrading to spray 1.2

After updating to spray 1.2 I got a problem regarding my JSON-Marshallers that worked perfectly with 1.1. Doing the following inside a HttpService

trait TestHttpService extends HttpService with SprayJsonSupport with DefaultJsonProtocol{ self : ActorLogging =>
    case class Test(hallo: String, test: String)
    implicit val storyJsonFormat = jsonFormat2(Test.apply)

    def test(implicit m : Marshaller[Future[Test]]) = 17
    def hallo = test 
}

leads to the following error:

could not find implicit value for parameter marshaller:
spray.httpx.marshalling.Marshaller[scala.concurrent.Future[amanuensis.story.Story]]

When I just remove the future everything works well:

trait TestHttpService extends HttpService with SprayJsonSupport with DefaultJsonProtocol { self : ActorLogging =>
    case class Test(hallo: String, test: String)
    implicit val storyJsonFormat = jsonFormat2(Test.apply)

    def test(implicit m : Marshaller[Test]) = 17
    def hallo = test

}

So the Marshaller for Story itself seems to be in implicit-scope. I am confused now since I never had to do anything else to be able to marshal futures before.

I really would appreciate a hint, what I am doing wrong here...

like image 824
jens Avatar asked Nov 06 '13 10:11

jens


1 Answers

Ok, solution is easy but quite hard to find since there is no error message pointing to it:

You need to specify an implicit execution context in scope to be able to use the also implicit Marshaller[Future[...]]. In my case:

trait TestHttpService extends HttpService with SprayJsonSupport with DefaultJsonProtocol{ self : ActorLogging =>
    //the following line was missing
    implicit def executionContext = actorRefFactory.dispatcher
    //
    case class Test(hallo: String, test: String)
    implicit val storyJsonFormat = jsonFormat2(Test.apply)

    def test(implicit m : Marshaller[Future[Test]]) = 17
    def hallo = test 
}

This was not the case with spray 1.1, Scala 2.10.0 and akka 2.1

like image 107
jens Avatar answered Oct 09 '22 07:10

jens