首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到参数封送器的隐式值: spray.httpx.marshalling.ToResponseMarshaller

找不到参数封送器的隐式值: spray.httpx.marshalling.ToResponseMarshaller
EN

Stack Overflow用户
提问于 2013-12-05 19:22:06
回答 1查看 9.8K关注 0票数 3

我在用

代码语言:javascript
复制
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,

并得到这个错误:

找不到参数封送器的隐式值: spray.httpx.marshalling.ToResponseMarshaller[Listorg.bwi.models.Cluster]

使用此代码:

代码语言:javascript
复制
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 *****
                }
            }
        }
}

}

我尝试过这个建议on this question,但它没有工作,同样的错误。

我似乎不知道我需要导入什么隐式。任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-05 22:42:27

您需要确保Cluster类型的隐式Cluster在作用域中,以便SprayJsonSupport知道如何对该类型进行强制转换。这样,您就可以自动从默认格式获得封送List[Cluster]的支持。

在发布的代码中,val impCluster = jsonFormat2(Cluster)定义了JsonFormat,但它没有被标记为implicit,因此不能隐式解析类型类型。改到

代码语言:javascript
复制
implicit val impCluster = jsonFormat2(Cluster)

应该解决这个问题。

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

https://stackoverflow.com/questions/20408734

复制
相关文章

相似问题

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