Map [String, Object] from a database (or key store) into a Shapeless Extensible Record
Example:
Let's say I have a map
val fromDB: Map[String, Any] = Map("name" -> "John", "age" -> 25)
Knowing that the "name" field should be a string, and the "age" field should be an integer, how would I convert this to a Shapeless Extensible Record, as shown below?
val user = ("name" ->> "John") :: ("age" ->> 25) :: HNil
My ultimate goal is to create an object, as shown below, that can transform a map using the "fromDB" function using fields.
object User { object name extends FieldOf[String] object age extends FieldOf[Int] def fromDB(data: Map[String,Any]) = {
I am open to other suggestions and ways to do this. Thanks.
scala shapeless
Simon c
source share