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

家住魔仙堡 提交于 2019-12-05 19:17:50

问题


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...


回答1:


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



来源:https://stackoverflow.com/questions/19809984/spray-marshaller-for-futures-not-in-implicit-scope-after-upgrading-to-spray-1-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!