1

i'm trying to marshall a string into a custom case class that I have. Here is the code I am trying to use

import spray.httpx.SprayJsonSupport._
import NflWeekJsonProtocol._
    path("playerScore") {
      get {
        parameters('gsisId.as[String] ?, 'week.as[NflWeek] ?, 'playerId.as[String]).as(PlayerScoreRequest) {
          playerScoreRequest : PlayerScoreRequest =>

        }
      }
    }

and here is the error that I am getting:

[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 represents a way to serializes the case class NflWeek. I thought this was all I would be required to do to get this working, what am I missing?

EDIT:

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)
    }
  }
}
Chris Stewart
  • 1,641
  • 2
  • 28
  • 60

1 Answers1

0

spray docs suggests you need parens, not square braces, when using a custom deserializer, .as(NflWeek)

corn_dog
  • 171
  • 6