I have a lot of implicit val for enum to json transformations in my program like that:
implicit val format = new Format[AuthRoleIndividual] {
def reads(json: JsValue) = JsSuccess(AuthRoleIndividual.withName(json.as[String]))
def writes(myEnum: AuthRoleIndividual) = JsString(myEnum.toString)
}
Note: AuthRoleIndividual extends Enumeration. My approach was to write something like that:
implicit val format[T <: Enumeration] = new Format[T] {
def reads(json: JsValue) = JsSuccess(T.withName(json.as[String]))
def writes(myEnum: T) = JsString(myEnum.toString)
}
But that's not possible. Any ideas?
WritesandReadsfor enumerations - cchantep