I need some hints to write a scala program that could read json file and create a case class at run time. As an example if we have json class like -
Employ{
name:{datatype:String, null:false}
age:{datatype:Int, null:true}
Address:{city: {datatype: String, null:true}, zip: {datatype: String, null:false}}
}
and this should create class like
case class Employ(name: String, age: Option[Int], address: Address}
case class Address(city: Option[String], zip:String}
would it be possible to do it in scala?
Yes, you can easily achieve this using TreeHugger. I did a similar thing for one of my work projects.
Below is a toy example which produces a Scala Akka Actor class. It needs to be cleaned up but, hopefully, you get the idea:
Essentially all you need to do is work out how to use the TreeHugger macros; each macro represents a specific keyword in Scala. It gives you a type-safe way to do your meta-programming.
There's also Scala Meta but I haven't used that.