0
是否可以使用以下级别的抽象级别在Scala中使用Typesafe Config和pureconfig创建以下方法? 我知道定义的案例分类配置读者必须被指定为follows,因为以下limitations ...但任何类型的案例类...如果他们都实施了他们的配置读者?找不到参数阅读器的隐含值:pureconfig.ConfigReader [T]
/**
* @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")
}
}
}