Hi Is it possible to declare a list of Json object...
# ktor
j
Hi Is it possible to declare a list of Json objects in the config file and read it with the config.property? we have something like this:
Copy code
key : [
{
  aKey: aValue
},
{
  bKey: bValue
}
]
....
IJ suggesting me one of those but I am not sure which one to use
a
Copy code
val objects = environment.config.configList("key")
println(objects[0].property("aKey").getString())
println(objects[1].property("bKey").getString())
j
@Aleksei Tirman [JB] thanks worked Another related question: is there a way to get the key value (in my example the aKey and the bKey ) ?
a
Do you mean to get keys of all objects in an array?
j
I mean to be able to old the objects as a map [“aKey”:“aValue”,….]
a
You can iterate over a list of objects and then get their keys using keys() method but this functionality will be available only in Ktor 2.0.0.
As a workaround, you use the solution described here.
j
thanks but I was trying to avoid the use of ConfigurationFactory since I am passing the ktor config as a parameter for tests purpose , I will hack it with hardcoded value for now and will wait for Ktor 2.0.0 Thanks a lot
c
@Jgafner You can use Config4k to convert application.conf to the kotlin data class and pass it as parameter https://github.com/config4k/config4k
j
thanks @csieflyman will take a look
j
thanks 🙏