jen*_*ens 9 scala future akka 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
}
Run Code Online (Sandbox Code Playgroud)
导致以下错误:
could not find implicit value for parameter marshaller:
spray.httpx.marshalling.Marshaller[scala.concurrent.Future[amanuensis.story.Story]]
Run Code Online (Sandbox Code Playgroud)
当我删除未来时,一切运作良好:
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
}
Run Code Online (Sandbox Code Playgroud)
所以Marshaler for Story本身似乎处于隐式范围内.我现在感到困惑,因为我以前从来没有做任何事情能够组织未来.
我真的很感激一个提示,我在这里做错了什么......
jen*_*ens 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
}
Run Code Online (Sandbox Code Playgroud)
喷雾1.1,Scala 2.10.0和akka 2.1不是这种情况
| 归档时间: |
|
| 查看次数: |
2463 次 |
| 最近记录: |