<https://github.com/config4k/config4k> Config4k is...
# announcements
m
https://github.com/config4k/config4k Config4k is a lightweight Typesafe Config wrapper for Kotlin. Config4k provides simple extension functions
com.typesafe.config.Config.extract<T>
and
Any.toConfig
to convert between
Config
and Kotlin Objects.
Copy code
data class Person(val name: String, val age: Int)
data class Family(val list: List<Person>)

// typesafe config supports not only HOCON but also JSON
// HOCON(Human-Optimized Config Object Notation) is the JSON superset
val config = ConfigFactory.parseString("""
                                         | // HOCON style
                                         |family {
                                         | list = [{
                                         |  name = "foo"
                                         |  age = 20
                                         | }, {
                                         |  name = "bar"
                                         |  age = 25
                                         | }]
                                         |}""".trimMargin())

// only typesafe config
val list = config.getList("family.list")
val foo = list[0].atKey("foo").run {
  Person(getString("foo.name"), getInt("foo.age"))
}
val bar = list[1].atKey("bar").run {
            Person(getString("bar.name"), getInt("bar.age"))
}
Family(listOf(foo, bar))

// typesafe config + config4k
config.extract<Family>("family")