我正在尝试将字符串编组到我拥有的自定义案例类中。这是我尝试使用的代码
import spray.httpx.SprayJsonSupport._
import NflWeekJsonProtocol._
path("playerScore") {
get {
parameters('gsisId.as[String] ?, 'week.as[NflWeek] ?, 'playerId.as[String]).as(PlayerScoreRequest) {
playerScoreRequest : PlayerScoreRequest =>
}
}
}
这是我得到的错误:
[error] /home/chris/dev/suredbits-dfs/src/main/scala/com/suredbits/dfs/nfl/scoring/NflPlayerScoringService.scala:40: too many arguments for method parameters: (pdm: spray.routing.directives.ParamDefMagnet)pdm.Out
[error] parameters('gsisId.as[String] ?, 'week.as[NflWeek] ?, 'playerId.as[String]).as(PlayerScoreRequest) {
[error] ^
[error] one error found
NflWeekJsonProtocol
表示一种对案例类进行序列化的方法NflWeek
。我以为这就是我需要做的所有事情才能让它工作,我错过了什么?
编辑:
object NflWeekJsonProtocol extends DefaultJsonProtocol {
implicit object NflWeekFormat extends RootJsonFormat[NflWeek] {
override def read(jsValue: JsValue) = {
jsValue match {
case JsString(string) => NflWeekFactory.factory(string)
case _ => throw new RuntimeException("NFLWeek should always be reprsented by a JsString")
}
}
override def write(week: NflWeek) = {
JsString(week.toString)
}
}
}