config
config copied to clipboard
Unable to merge two configs
I have two conf files - application.conf and sample.conf
application.conf
{
"mylist" {
"records": [
{
"fileName": "path/to/file1.java",
"lastModified": "0",
},
{
"fileName": "path/to/file2.java",
"lastModified": "0",
}
]
}
xyz : true
}
sample.conf
{
"mylist": {
"records": [
{
"fileName": "path/to/file3.java",
"lastModified": "",
},
{
"fileName": "path/to/file4.java",
"lastModified": "",
}
]
}
}
Now,
Config mylistConfig = ConfigFactory.parseFile(new File("sample.conf"));
Config appConfig = ConfigFactory.load();
public Config getMergedConfig() {
return ConfigFactory.load(mylistConfig).withFallback(appConfig);
}
The above function instead of merging overwrites. Only shows me result of mylist from sample.conf or application.conf whatever is written first in load-fallback order.. Do the list in confs gets overwritten ?
Is there any way to get records from both conf files ?
only objects auto-merge. to concat lists or strings you need to put in a substitution like ${mylist.records} [ “concat this value” ]
@havocp Thanks for replying.
I was also checking out the concatenation operatoe.
Let's say I want to take values of application.conf as :
{
"mylist" {
"records":[]
"records" += [
{
"fileName": "path/to/file1.java",
"lastModified": "0",
},
{
"fileName": "path/to/file2.java",
"lastModified": "0",
}
]
}
xyz : true
}
But I get an error now : records has type list of LIST rather than list of OBJECT
Any idea with this ?
only objects auto-merge. to concat lists or strings you need to put in a substitution like
${mylist.records} [ “concat this value” ]
@havocp Are you suggesting :
{
"mylist" {
"records" : []
"records" = ${?whitelist.records} [
{
"fileName": "path/to/file1.java",
"lastModified": "0",
},
{
"fileName": "path/to/file2.java",
"lastModified": "0",
}
]
}
xyz : true
}
Using this in application.conf should merge both whitelist object in both configs using withFallback() ?