加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

斯卡拉 – 喷雾马歇尔为升级后喷雾1.2毫米隐含范围内的期货

发布时间:2020-12-16 19:00:28 所属栏目:安全 来源:网络整理
导读:更新到spray 1.2后,我遇到了一个与我的 JSON编程器完美配合的问题.在HttpService中执行以下操作 trait TestHttpService extends HttpService with SprayJsonSupport with DefaultJsonProtocol{ self : ActorLogging = case class Test(hallo: String,test: S
更新到spray 1.2后,我遇到了一个与我的 JSON编程器完美配合的问题.在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 [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不是这样

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读