Could it be even possible to create the following method with the following level of abstraction with Typesafe Config and pureconfig in scala ? I am aware for defined Case Classes that Config Reader has to be specified as follows , because of the following limitations ... but what about Any Type of Case class ... if they all have their ConfigReaders implemented ?
/**
* @param path the.path.to.the.branch
* @param config the com.typesafe.config obj
* @tparam T - the type of the case class obj
* @return the filled-in obj of type T
*
*/
def getConfigType[T](path: String, config :Config) :Option[T] = {
val renderOpts = ConfigRenderOptions.defaults
.setOriginComments(false).setComments(false).setJson(true)
val levelConfig :Config = config.getConfig(path)
val strConfig: String = config.getConfig(path).root().render(renderOpts)
loadConfig[T](ConfigFactory.parseString(strConfig)) match {
case Right(objFilledCaseClass) => Some(objFilledCaseClass)
case Left(errors) => throw new RuntimeException(s"Invalid configuration: $errors")
}
}
}