[英]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.