只是尝试一下 spray-json,似乎在找到我设置的 JsonProtocols 时遇到了问题。我有以下依赖项:
"io.spray" % "spray-servlet" % "1.2-M8",
"io.spray" % "spray-routing" % "1.2-M8",
"io.spray" % "spray-testkit" % "1.2-M8",
"io.spray" % "spray-json_2.10" % "1.2.5"
以及以下代码:
Content.scala
import spray.json.DefaultJsonProtocol
case class Content(id:String, name: String, contentType: String, duration: Int)
object MyJsonProtocol extends DefaultJsonProtocol {
implicit val contentFormat = jsonFormat4(Content)
}
我Content
在complete {}
块中返回的行出现错误,错误如下,代码在其下方:
描述资源路径位置类型找不到类型spray.httpx.marshalling.Marshaller [Content] MyService.scala第32行Scala问题的证据参数的隐式值
import akka.actor.Actor
import spray.routing._
import spray.http._
import MediaTypes._
import spray.json.DefaultJsonProtocol
import Content
import MyJsonProtocol._
class MyServiceActor extends Actor with MyService{
def actorRefFactory = context
def receive = runRoute(myRoute)
}
trait MyService extends HttpService {
val myRoute =
path("") {
get {
respondWithMediaType(`application/json`) { // XML is marshalled to `text/xml` by default, so we simply override here
complete {
new Content("1234", "Some Content", "YT", 60)
}
}
}
}
}
有人能看出有什么不对吗?这实际上是带有spray-json内容的spray-template代码