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")
}
}
}