spray / spray-json

A lightweight, clean and simple JSON implementation in Scala
Apache License 2.0
972 stars 190 forks source link

Companion object with jsonFormat not working as in example #193

Open favetelinguis opened 8 years ago

favetelinguis commented 8 years ago

Having trouble with getting the follwoing code workign as expected from the examples in the first page here on github.

case class SessionKey(sessionKey: String) extends PublicFeedArgsType
object SessionKey {
  def makeSessionKey (key: String): Try[SessionKey] = {
    if (!validator(key))
      throw new Exception("Session key not valid")
    else
      Success(SessionKey(key))
  }
  private def validator(key: String):Boolean = {
    true
  }
}

trait DomainModelJsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
  implicit val sessionKeyFormat = jsonFormat(SessionKey.apply, "session_key")
}

SessionKey.apply gives me the error

Missing arguments for method apply(String). Cannot resolve reference apply with such signature.

Any suggestions where this is different from the examples?