Let’s say I have a HashMap:
val userMap = new HashMap[String, String]
userMap += "username" -> "user"
userMap += "password" -> "pass"
and an Object:
username:String = ""
password:String = ""
What would be the best way to put the values from the HashMap into the object, without using the Java Reflection API (with or without Annotations)?
It might be similar to that question: Scala – Lift – map a custom boxed object for bind?
Since you don’t want reflection, you can’t match up the names automatically. But doing it manually isn’t hard.
Given
I would just
which will give you an
Option[User]withSomeuser if it is in that map, andNoneif not.