更新到喷雾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本身似乎是在隐式范围内。我现在很困惑,因为我以前从来没有做任何其他事情能够组织未来。
我真的很感激提示,我在这里做错了什么......
答案 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
不是这种情况