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
}
Source: stackoverflow.com
Related Query
- How to implement enums in scala slick 3?
- How to implement enums with values in Scala 2.12.15
- How to implement Map with default operation in Scala
- How do I implement a generic mathematical function in Scala
- How do I pass Scala enums as parameters?
- How does Scala Slick translate Scala code into JDBC?
- How do I implement a collection in Scala 2.8?
- How to implement breadth first search in Scala with FP
- How can I negate "inSet" in a Scala Slick query?
- Scala Slick / ScalaQuery BigDecimal creates decimal(10,0) how to allow decimals?
- How do I implement Kafka Consumer in Scala
- How do you change lifted types back to Scala types when using Slick lifted embedding?
- scala 3 macro how to implement generic trait
- How to elegantly implement the pipeline pattern using Scala
- How to implement Scala apply method in Java
- How to create a general method for Scala 3 enums
- How to use Enums in Scala Slick?
- How to implement Lazy Chain Pattern in Scala
- How to send plain SQL queries (and retrieve results) using scala slick 3
- Slick 3: How to implement repository pattern with transactions?
- How does one implement a Hadoop Mapper in Scala 2.9.0?
- How to implement a short-circuit with IO monad in Scala
- how to implement this future/state concept as a monad in scala
- How to mock db in Scala Slick
- How does Scala implement return from within an expression?
- How to implement Java interface in Scala with multiple variable parameter methods (type eraser issue)?
- How to implement a recursive Fibonacci sequence in Scala using FS2?
- How to implement types like MapK in Scala 3 / Dotty?
- How to implement org.hibernate.Session in Scala
- How to implement tail-recursive quick sort in Scala
More Query from same tag
- Scala Compiler doesn't compile in ScalaIDE
- Passing through Left statement in Either
- Why do mutable and immutable ListMaps have different orders in Scala?
- Intellij Fails to Import SBT project
- Case Class default apply method
- create an RDD using Spark hadoop API to access Cassandra DB
- Scala Lift: uniform authentication with form based login and HTTP basic auth?
- Why memory sink writes nothing in append mode?
- java.lang.IllegalArgumentException: Field "label" does not exist using SparkML
- flatMap strange behaviour on List of List of Integers
- finding a substring in a text column that start and end with a specific string
- How to populate last not null data into column?
- Simple cross platform GUI app
- Does scala.sys.process block on stream processing threads?
- Replace randomly RDD values to null with scala spark
- Scala: Task not serializable in RDD map Caused by json4s "implicit val formats = DefaultFormats"
- Reflection with Typeclasses
- What is mentioned inside the parameters of SciSpark netcdf file using scala?
- Closing an Akka stream from inside a GraphStage (Akka 2.4.2)
- How to use from_json standard function with custom schema (error: overloaded method value from_json with alternative)?
- How to implement pluralize & other extensions using Playframework 2.0
- Scala: generic parser for Enumeration values
- Scala seemingly ignoring some code
- Adding module dependency information in sbt's build.sbt file
- org.apache.thrift.transport.TTransportException error while Reading large JSON file in zeppelin scala
- Simple feeder in Gatling without using a csv file
- Length of dataframe inside UDF function
- Calling foldLeft on Buffer from Java
- Override whole class in java/scala
- How to auto generate the with... type method in intellij