Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala Akka HTTP客户端-使用Play JSON解组_Scala_Unmarshalling_Akka Http_Play Json - Fatal编程技术网

Scala Akka HTTP客户端-使用Play JSON解组

Scala Akka HTTP客户端-使用Play JSON解组,scala,unmarshalling,akka-http,play-json,Scala,Unmarshalling,Akka Http,Play Json,我使用Akka HTTP作为客户端来执行POST请求并解析答案。我正在使用Play JSON,出现以下编译器错误: could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.Unmarshaller[akka.http.javadsl.model.ResponseEntity,B] [ERROR] Unmarshal(response.entity).to[B].recoverWi

我使用Akka HTTP作为客户端来执行POST请求并解析答案。我正在使用Play JSON,出现以下编译器错误:

could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.Unmarshaller[akka.http.javadsl.model.ResponseEntity,B]
[ERROR]       Unmarshal(response.entity).to[B].recoverWith {
这是我为使用Play JSON而不是Spray添加的依赖项:

"de.heikoseeberger" %% "akka-http-play-json"
我的班级定义是:

class HttpClient(implicit val system: ActorSystem, val materializer: Materializer) extends PlayJsonSupport {
private def parseResponse[B](response: HttpResponse)(implicit reads: Reads[B]): Future[B] = {
  if (response.status().isSuccess) {
    Unmarshal(response.entity).to[B].recoverWith {
    ....
方法定义为:

class HttpClient(implicit val system: ActorSystem, val materializer: Materializer) extends PlayJsonSupport {
private def parseResponse[B](response: HttpResponse)(implicit reads: Reads[B]): Future[B] = {
  if (response.status().isSuccess) {
    Unmarshal(response.entity).to[B].recoverWith {
    ....
在进口中,我有:

import play.api.libs.json._
import scala.concurrent.ExecutionContext.Implicits.global
import de.heikoseeberger.akkahttpplayjson.PlayJsonSupport._

在我看来,我在其范围内具有所需的含义。
封送处理
部分具有类似的逻辑(但具有
写入
而不是
读取
),并且编译良好。我遗漏了什么?

检查您的其他导入。根据错误消息,您使用的似乎是
akka.http.javadsl.model.HttpResponse
,而不是
akka.http.scaladsl.model.HttpResponse
;仅支持Scala DSL:

private def parseResponse[B](response: HttpResponse)(implicit reads: Reads[B]): Future[B] = ???
                                    // ^ this should be akka.http.scaladsl.model.HttpResponse
换句话说,使用

import akka.http.scaladsl.model._
而不是

import akka.http.javadsl.model._

检查您的其他导入。根据错误消息,您使用的似乎是
akka.http.javadsl.model.HttpResponse
,而不是
akka.http.scaladsl.model.HttpResponse
;仅支持Scala DSL:

private def parseResponse[B](response: HttpResponse)(implicit reads: Reads[B]): Future[B] = ???
                                    // ^ this should be akka.http.scaladsl.model.HttpResponse
换句话说,使用

import akka.http.scaladsl.model._
而不是

import akka.http.javadsl.model._

哦哇!愚蠢的错误。我用IntelliJ自动添加了导入,甚至没有注意到这一点。另一双眼睛总是有帮助的,非常感谢!哦哇!愚蠢的错误。我用IntelliJ自动添加了导入,甚至没有注意到这一点。另一双眼睛总是有帮助的,非常感谢!