I have problem with upgrading from Slick 1.0 to Slick 2.0 in my Play apllication.
In my app I have some User defined types example:
sealed trait UserStatus
case object NewUser extends UserStatus
case object ActiveUser extends UserStatus
case object BlockedUser extends UserStatus
object UserStatus extends SerializableEnum[UserStatus] {
def mapping = Map[String, UserStatus](
"NEW" -> NewUser,
"ACTIVE" -> ActiveUser,
"BLOCKED" -> BlockedUser
)
}
and generic mapper for slick 1.0:
trait SerializableEnum[T] {
def mapping: Map[String, T]
def reverseMapping = mapping.map(_.swap)
implicit def enumWrites = new Writes[T] {
def writes(o: T): JsValue = JsString(reverseMapping(o))
}
implicit val enumReads = new Reads[T] {
def reads(json: JsValue): JsResult[T] = json match {
case JsString(s) => JsSuccess(mapping(s))
case _ => JsError("Enum type should be of proper type")
}
}
implicit val enumTypeMapper = MappedTypeMapper.base[T, String](reverseMapping, mapping)
}
After migration to Slick 2.0, new mapper wasn't work:
trait SerializableEnum[T] {
def mapping: Map[String, T]
def reverseMapping:Map[T,String] = mapping.map(_.swap)
implicit def enumWrites = new Writes[T] {
def writes(o: T): JsValue = JsString(reverseMapping(o))
}
implicit val enumReads = new Reads[T] {
def reads(json: JsValue): JsResult[T] = json match {
case JsString(s) => JsSuccess(mapping(s))
case _ => JsError("Enum type should be of proper type")
}
}
implicit val enumTypeMapper = MappedColumnType.base[T, String](reverseMapping, mapping)
}
Compiler says:
No ClassTag available for T
It is not possible to define ClassTag type for trait. Does anybody have idea how to resolve it?
I prepared example app for this: https://github.com/mgosk/slick-test