假设我有两个配置文件:
val config1: Config = ...
val config2: Config = ...
我希望将与someKey
的密钥config1
对应的键值对复制到config2
。键值如下所示:
someKey: ["someVal", "someVal2"]
这是我先做的事情:
val config3 = config2.withValue("someKey",
ConfigValueFactory.fromIterable(config1.getStringList("someKet")))
非常难看。我也尝试了,但它给出了错误has type LIST rather than OBJECT
:
val config3 = config2.withFallback(config1.getConfig("someKey"))
有关如何以更清洁的方式执行此操作的任何想法?
答案 0 :(得分:0)
这个怎么样:
val c1: Config = ConfigFactory.parseString("x.a = 3 \n x.b = 'bbb' \n x.c = [1, 2, 3]")
val c2: Config = ConfigFactory.parseString("x.a = 4")
println(c1)
println("-----------")
println(c2)
println(c1.getInt("x.a"))
println(c2.withValue("x.c", c1.getList("x.c")))