在升级到喷雾1.2后,喷射Marshaller的期货不在隐含范围内

时间:2013-11-06 10:45:08

标签: scala akka future spray

更新到喷雾1.2后,我遇到了一个与我的JSON-Marshallers完美配合的问题。在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 
}

导致以下错误:

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

当我删除未来时,一切运作良好:

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

}

所以Marshaller for Story本身似乎是在隐式范围内。我现在很困惑,因为我以前从来没有做任何其他事情能够组织未来。

我真的很感激提示,我在这里做错了什么......

1 个答案:

答案 0 :(得分:18)

好的,解决方案很简单,但很难找到,因为没有指向它的错误消息:

您需要在范围中指定隐式执行上下文,以便能够使用隐式Marshaller [Future [...]]。就我而言:

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 
}

喷雾1.1,Scala 2.10.0和akka 2.1

不是这种情况