gpt4 book ai didi

spray-json - akka-http 错误 : could not find implicit value for parameter um: akka. http.scaladsl.unmarshalling.FromRequestUnmarshaller

转载 作者:行者123 更新时间:2023-12-03 09:36:02 24 4
gpt4 key购买 nike

我知道已经有人问过了,但我似乎找不到答案。
这是我的代码:

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport
import spray.json.DefaultJsonProtocol

final case class Client(clientId:Int, clientName:String, platformIds:Int, host:String, password:String)

object ClientJson extends DefaultJsonProtocol with SprayJsonSupport {
implicit val clientFormat = jsonFormat5(Client)
}

class HTTPListenerActor extends Actor with ImplicitMaterializer with RoadMap {

implicit val conf = context.system.settings.config
implicit val system = context.system
implicit val ec = context.dispatcher


Await.result(Http().bindAndHandle(roads, "interface", 8080), Duration.Inf)

override def receive:Receive = Actor.emptyBehavior
}

trait RoadMap extends Directives {

val roads: Route = path("client"/IntNumber) { id =>
import ClientJson._
post {
entity(as[Client]) { c => complete {c} }
}
}
}

此代码生成错误
 [ant:scalac] /Users/smalov/Workspace/api-service/src/main/scala/com/acheron/HTTPListenerActor.scala:51: error: could not find implicit value for parameter um: akka.http.scaladsl.unmarshalling.FromRequestUnmarshaller[com.acheron.Client]
[ant:scalac] entity(as[Client]) { c =>

现在,这种错误的最常见原因是忘记将隐式编码导入 roads 附近的作用域中。定义不过,我没有忘记这一点。另一个原因可能是我隐含了 FlowMaterializer在范围内而不是 ActorMaterializer ,但是 ImplictMaterializer trait 解决了这个问题。

还有什么我可能会错过的吗?

我正在使用 Scala 2.11.7、Akka 2.3.11、akka-http 1.0、spray-json 1.3.2

最佳答案

我也遇到了同样的错误,导入后解决了

import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._
可能这会有所帮助

关于spray-json - akka-http 错误 : could not find implicit value for parameter um: akka. http.scaladsl.unmarshalling.FromRequestUnmarshaller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33663732/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com