简体   繁体   English

找不到参数marshaller的隐含值:spray.httpx.marshalling.ToResponseMarshaller

[英]could not find implicit value for parameter marshaller: spray.httpx.marshalling.ToResponseMarshaller

I'm using 我正在使用

val akkaV = "2.2.3"
val sprayV = "1.2.0"
Seq(
  "io.spray"            %   "spray-can"     % sprayV,
  "io.spray"            %   "spray-routing" % sprayV,
  "io.spray"          %%  "spray-json"    % "1.2.5",
  "io.spray"            %   "spray-testkit" % sprayV,
  "com.typesafe.akka"   %%  "akka-actor"    % akkaV,
  "com.typesafe.akka"   %%  "akka-testkit"  % akkaV,

And getting this error: 并收到此错误:

could not find implicit value for parameter marshaller: spray.httpx.marshalling.ToResponseMarshaller[List[org.bwi.models.Cluster]] 找不到参数marshaller的隐含值:spray.httpx.marshalling.ToResponseMarshaller [List [org.bwi.models.Cluster]]

with this code: 使用此代码:

object JsonImplicits extends DefaultJsonProtocol {
val impCluster = jsonFormat2(Cluster)

}

trait ToolsService extends HttpService with spray.httpx.SprayJsonSupport {

val myRoute = {

    import JsonImplicits._

    path("") { get { getFromResource("tools.html") } } ~
        pathPrefix("css") { get { getFromResourceDirectory("css") } } ~
        pathPrefix("fonts") { get { getFromResourceDirectory("fonts") } } ~
        pathPrefix("js") { get { getFromResourceDirectory("js") } } ~
        path("clusters") {
            get {
                complete {
                    val result: List[Cluster] = List(Cluster("1", "1 d"), Cluster("2", "2 d"), Cluster("3", "3 d"))
                    result //*****   ERROR OCCURS HERE *****
                }
            }
        }
}

} }

I've tried the suggestion on this question but it did not work, same error. 我已经尝试过关于这个问题的建议但它没有用,同样的错误。

I can't seem to figure out what the implicit I need to import is. 我似乎无法弄清楚我需要导入的隐含内容。 Any help would be appreciated. 任何帮助,将不胜感激。

You need to make sure that the implicit JsonFormat for the Cluster type is in scope, so that SprayJsonSupport knows how to marshall that type. 您需要确保Cluster类型的隐式JsonFormat在范围内,以便SprayJsonSupport知道如何编组该类型。 With that you should automatically get support for marshaling List[Cluster] from the default formats. 有了这个,您应该自动获得默认格式的封送List[Cluster]编组支持。

In the posted code val impCluster = jsonFormat2(Cluster) defines the JsonFormat , but it is not marked as implicit , so the typeclass cannot be implicitly resolved. 在发布的代码中, val impCluster = jsonFormat2(Cluster)定义了JsonFormat ,但它没有标记为implicit ,因此无法隐式解析类型类。 Changing it to 把它改成

implicit val impCluster = jsonFormat2(Cluster)

should fix the issue. 应该解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找不到参数编组器的隐式值:spray.httpx.marshalling.ToResponseMarshaller [Unit] - could not find implicit value for parameter marshaller: spray.httpx.marshalling.ToResponseMarshaller[Unit] Spray,ScalaTest和HTTP服务:找不到参数ta的隐式值: - Spray, ScalaTest and HTTP services: could not find implicit value for parameter ta: spray-json错误:无法找到参数um的隐含值 - spray-json error: could not find implicit value for parameter um 错误无法将值隐含到ToResponseMarshaller [SearchResponse] - Error Could Not Implicit Value ToResponseMarshaller[SearchResponse] spray-json递归json问题-找不到证据参数的隐式值 - spray-json recursive json issue - could not find implicit value for evidence parameter 使用spray.json序列化多态类获取无法找到类型为证据的隐式值 - serializing polymorphic classes using spray.json getting could not find implicit value for evidence parameter of type 这作为隐式参数-找不到参数的隐式值 - this as implicit parameter - could not find implicit value for parameter 原因“找不到参数rs的隐式值:spray.routing.RoutingSettings” - Reason for “could not find implicit value for parameter rs: spray.routing.RoutingSettings” spray-json:找不到FromRequestUnmarshallar的隐式值 - spray-json: could not find implicit value for FromRequestUnmarshallar 无法找到参数的隐含值 - Could not find implicit value for parameter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM