升级到1.2版本后,将Marshaller的期货未纳入隐含范围 [英] spray Marshaller for futures not in implicit scope after upgrading to spray 1.2

查看:79
本文介绍了升级到1.2版本后,将Marshaller的期货未纳入隐含范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在更新为Spray 1.2之后,我遇到了与1.1完美配合的JSON-Marshallers问题。在HttpService中执行以下操作

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 
}

会导致以下结果错误:

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

当我删除未来时,一切都很好: / p>

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

}

因此,Marshaller因为Story本身似乎处于隐式范围内。现在我很困惑,因为我以前从来不需要做任何其他事情就可以封存期货。

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

推荐答案

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

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

您需要在范围内指定隐式执行上下文,以便能够使用隐式的Marshaller [Future [...]]。在我的情况下:

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 
}

spray 1.1,Scala 2.10.0和akka 2.1并非如此

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

这篇关于升级到1.2版本后,将Marshaller的期货未纳入隐含范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆