Hello all,
After working in Java for a long time, I started to get interested in Scala. As a learning project, I am trying to duplicate a java library that stores and retrieves state objects from the database. For this, I would like to be able to just specify a state object like this:
@PersistName("PERSON") case class Person extends Entity {
@Persist var id:Long = -1
@Persist @MaxLength(80) var firstName = ""
@Persist @MaxLength(80) var lastName = ""
@Persist var gender = Gender.Male
@Persist @MaxLength(80) var userName = ""
@Persist @OptionClass(classOf[Date]) var birthDay:Option[Date] = None
}
The code to serialize/un-serialize an instance of Person uses reflection to know the types of fields and works ok for all but the gender field. The gender field is an Enumeration that is defined as:
object Gender extends Enumeration { type Gender = Value val Male,Female,Unknown = Value } The problem is that I don’t know how I can use reflection too create a new Gender value using only the Person class.