1
votes

Without using shapeless library, can we create a case class dynamically using some bunch of Strings? (Array of strings or list of strings)

I have a list of strings and I want to some how create a case class instance so that I can map them to some other table.

For example, let's say, these are the strings

DRUG_NAME, DRUG_TYPE, COMPANY, STATE, OFFICER

I want them to be in case class, like this:

case class DrugStore(DRUG_NAME: String, DRUG_TYPE: String, COMPANY: String, STATE: String, OFFICER: String)
1

1 Answers

3
votes

You could use reflection for that:

  classOf[DrugStore]
    .getConstructors 
    .head
    .newInstance(listOfParameters)
    .asInstanceOf[DrugStore]