Map[String,Object] from a DB (or Key Value store) to a Shapeless Extensible Record
Example:
Lets say I have a map
val fromDB: Map[String, Any] = Map("name" -> "John", "age" -> 25)
Knowing that the field "name" should be a string and the field "age" should be an integer, how would I convert that to a Shapeless Extensible Record as below?
val user = ("name" ->> "John") :: ("age" ->> 25) :: HNil
My end goal is to create an object as below that can convert the Map using the function "fromDB" using the fields.
object User {
object name extends FieldOf[String]
object age extends FieldOf[Int]
def fromDB(data: Map[String,Any]) = {
//TODO
}
}
I'm open to other suggestion and ways of doing this as well. Thanks.