Можно ли вообще создать следующий метод со следующим уровнем абстракции с помощью Typesafe Config и pureconfig в scala? Я знаю, что для определенных классов Case Config Reader должен быть указан как следует из-за следующего ограничения ... но как насчет класса Any Type of Case ... если во всех них реализованы их ConfigReaders?
/**
* @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")
}
}
}