我正在尝试Map[String, Any]
从配置文件中加载一个。目前是这样写的
map-name {
stringValue = "firstValue"
intValue = 1
booleanValue = true
}
Pureconfig 无法将此配置作为Map[String, Any]
. 它仅在替换Any
为某些严格类型时才有效,但我想要比这更大的灵活性。
有没有办法解决?
我正在尝试Map[String, Any]
从配置文件中加载一个。目前是这样写的
map-name {
stringValue = "firstValue"
intValue = 1
booleanValue = true
}
Pureconfig 无法将此配置作为Map[String, Any]
. 它仅在替换Any
为某些严格类型时才有效,但我想要比这更大的灵活性。
有没有办法解决?
有没有办法解决?
就在这里。您可以使用这种类型:Map[String, ConfigValue]
ConfigValue
来自其 Scala 文档:
一个不可变的值,遵循JSON类型架构。
但是你可以使用ConfigObject
而不是Map[String, ConfigValue]
,因为这是同一件事。
您现在可以像处理JSON-Object
结构一样处理它。
以下是一些示例:java-api-usage-examples。
I just want to replace values of an existing config. If I read in the whole config from the config file, I'll have to specify all the other values, even the ones I don't want to change.
This is newConfig.withFallback(oldConfig)
.
你可以有这样的东西:
import scala.collection.JavaConverters._
implicit val mapReader = pureconfig.ConfigReader[ConfigObject].map(co => co.unwrapped().asScala.toMap)