首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >方法解组:(隐式证据$1: spray.httpx.unmarshalling.FromResponseUnmarshaller )的参数不足

方法解组:(隐式证据$1: spray.httpx.unmarshalling.FromResponseUnmarshaller )的参数不足
EN

Stack Overflow用户
提问于 2016-02-19 07:51:42
回答 1查看 1.1K关注 0票数 1

我将从SprayJsonSupport传递到基于这个例子的argonaut。经过一些代码修改后:

代码语言:javascript
复制
object ElevationJsonProtocol extends DefaultJsonProtocol {
  implicit val locationCodec: CodecJson[Elevation] = casecodec2(Elevation, Elevation.unapply)("location", "elevation")
  implicit val elevationCodec: CodecJson[Location] = casecodec2(Location, Location.unapply)("lat", "lng")
  implicit def googleApiResultCodec: CodecJson[GoogleApiResult] = casecodec2(GoogleApiResult, GoogleApiResult.unapply)("status", "results")
}

我犯了这个错误

错误:(41,42)方法解组:(隐式证据$1: spray.httpx.unmarshalling.FromResponseUnmarshallerGoogleApiResult)spray.http.HttpResponse => GoogleApiResult )的参数不足。未指定的值参数证据$1.val管道= sendReceive ~> unmarshalGoogleApiResult ^

我来看看unmarshall的方法:

代码语言:javascript
复制
 def unmarshal[T](implicit evidence$1 : spray.httpx.unmarshalling.FromResponseUnmarshaller[T]) : scala.Function1[spray.http.HttpResponse, T] 

如何添加隐式参数?为什么我没有得到这样的错误与sprayJsonSupport?

洞码:

代码语言:javascript
复制
import spray.httpx.unmarshalling.FromResponseUnmarshaller

import scala.util.{Success, Failure}
import scala.concurrent.duration._
import akka.actor.ActorSystem
import akka.pattern.ask
import akka.event.Logging
import akka.io.IO
import spray.json.{JsonFormat, DefaultJsonProtocol}
import spray.can.Http
import spray.httpx.SprayJsonSupport
import spray.client.pipelining._
import spray.util._
import argonaut._, Argonaut._

case class Elevation(location: Location, elevation: Double)
case class Location(lat: Double, lng: Double)
case class GoogleApiResult(status: String, results: List[Elevation])

object ElevationJsonProtocol extends DefaultJsonProtocol {
  implicit val locationCodec: CodecJson[Elevation] = casecodec2(Elevation, Elevation.unapply)("location", "elevation")
  implicit val elevationCodec: CodecJson[Location] = casecodec2(Location, Location.unapply)("lat", "lng")
  implicit def googleApiResultCodec: CodecJson[GoogleApiResult] = casecodec2(GoogleApiResult, GoogleApiResult.unapply)("status", "results")
}

object Main extends App {
  // we need an ActorSystem to host our application in
  implicit val system = ActorSystem("simple-spray-client")
  import system.dispatcher // execution context for futures below
  val log = Logging(system, getClass)

  log.info("Requesting the elevation of Mt. Everest from Googles Elevation API...")

  import ElevationJsonProtocol._

  val pipeline = sendReceive ~> unmarshal[GoogleApiResult]

  val responseFuture = pipeline (
    Get("http://maps.googleapis.com/maps/api/elevation/json?locations=27.988056,86.925278&sensor=false")
    )

  responseFuture onComplete {
    case Success(GoogleApiResult(_, Elevation(_, elevation) :: _)) =>
      log.info("The elevation of Mt. Everest is: {} m", elevation)
      shutdown()

    case Success(somethingUnexpected) =>
      log.warning("The Google API call was successful but returned something unexpected: '{}'.", somethingUnexpected)
      shutdown()

    case Failure(error) =>
      log.error(error, "Couldn't get elevation")
      shutdown()
  }

  def shutdown(): Unit = {
    IO(Http).ask(Http.CloseAll)(1.second).await
    system.shutdown()
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-02-20 13:50:11

我不是真的用argonaut,我用的是喷雾器。但是,乍一看,似乎需要一个argonaut支持特性/导入,以便将您的隐式编解码器转换为for的解编组器( play json也需要类似的东西)。

https://github.com/dwhjames/argonaut-spray

这个图书馆似乎是你想要的。您的提示和导入看起来很好,使用库应该可以解决您的问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35500099

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档