score:18

Accepted answer

what exactly do you mean by mappedcolumntype is no longer available? it comes with the usual import of the driver. mapping an enum to a string and vice versa using mappedcolumntype is pretty straight forward:

object myenum extends enumeration {
  type myenum = value
  val a = value("a")
  val b = value("b")
  val c = value("c")
}

implicit val myenummapper = mappedcolumntype.base[myenum, string](
  e => e.tostring,
  s => myenum.withname(s)
)

score:2

a shorter answer so that you don't need to implement myenummapper yourself:

import play.api.libs.json.{reads, writes}

object myenum extends enumeration {
  type myenum = value
  val a, b, c = value // if you want to use a,b,c instead, feel free to do it

  implicit val readsmyenum = reads.enumnamereads(myenum)
  implicit val writesmyenum = writes.enumnamewrites
}

Related Query

More Query from same tag