无法解析隐藏的解组

时间:2015-07-02 15:18:38

标签: scala spray

鉴于这个简单的喷涂应用程序,它试图获得Foo的响应。

object Main extends App with SimpleRoutingApp {

  implicit val system = ActorSystem("my-system")

  case class Foo(x: String) 
  implicit val format = jsonFormat1(Foo)

  val pipeline: HttpRequest => Future[Foo] = sendReceive ~> unmarshal[Foo]

  val LOGIN_URL = "foo.bar.com/login"

  startServer(interface = "localhost", port = 8080) {
    path("go") {
      get {
        complete {
          val req = Post(LOGIN_URL)
          pipeline(req).recoverWith[Foo]{ case _ => Future { Foo("foo") } }
        }
      }
    }    
  }
}

我收到以下编译时错误:

[error] Main.scala:19: could not find implicit value for evidence parameter of type spray.httpx.unmarshalling.FromResponseUnmarshaller[net.Main.Foo]
[error]   val pipeline: HttpRequest => Future[Foo] = sendReceive ~> unmarshal[Foo]
[error]                                                                      ^
[error] Main.scala:35: type mismatch;
[error]  found   : scala.concurrent.Future[net.Main.Foo]
[error]  required: spray.httpx.marshalling.ToResponseMarshallable
[error]           pipeline(req).recoverWith[Foo]{ case _ => Future { Foo("foo") } }
[error]                                         ^

我原本预计implicit val format = ...会为Format提供隐式Foo

如何修复这些错误?

0 个答案:

没有答案