Reputation: 473
I'm trying to load up a Map[String, Any]
from the config file. It's currently written like this
map-name {
stringValue = "firstValue"
intValue = 1
booleanValue = true
}
Pureconfig is having trouble reading this config as a Map[String, Any]
. It only works if replace Any
with some strict type but I want more flexibility than this.
Is there any way around this?
Upvotes: 2
Views: 3509
Reputation: 843
You can have something like this:
import scala.collection.JavaConverters._
implicit val mapReader = pureconfig.ConfigReader[ConfigObject].map(co => co.unwrapped().asScala.toMap)
Upvotes: 0
Reputation: 170733
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)
.
Upvotes: 1
Reputation: 14803
Is there any way around this?
Yes there is. You can use this type: Map[String, ConfigValue]
ConfigValue
from its Scala Doc:
An immutable value, following the JSON type schema.
But then you can use ConfigObject
instead of Map[String, ConfigValue]
, as this is the same thing.
You can handle this now like a JSON-Object
structure.
Here are some examples: java-api-usage-examples.
Upvotes: 7