-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested collection of objects #17
Comments
@arunma You can use Kotlin data class for nested objects in collections. Konf will handle all the serialization stuff. Here is a runnable solution for your case: import com.uchuhimo.konf.Config
import com.uchuhimo.konf.ConfigSpec
val text = """
datasets:
hive:
- key: transactions
uri: /user/somepath
format: parquet
database: transations_daily
table: transx
- key: second_transactions
uri: /seconduser/somepath
format: avro
database: transations_monthly
table: avro_table
file:
- key: users
uri: s3://filestore
format: parquet
mode: overwrite
""".trimIndent()
object DatasetsSpec: ConfigSpec() {
val file by optional<List<FileDS>>(default = emptyList())
val hive by optional<List<HiveDS>>(default = emptyList())
}
data class FileDS(val key: String, val uri: String, val format: String = "parquet", val mode: String = "append")
data class HiveDS(val key: String, val uri: String, val database: String, val table: String, val format: String = "parquet", val mode: String = "append")
fun main(args: Array<String>) {
val config = Config { addSpec(DatasetsSpec) }.from.yaml.string(text)
check(config[DatasetsSpec.file][0].key == "users")
check(config[DatasetsSpec.hive][1].database == "transations_monthly")
} |
@uchuhimo This is excellent ! Love the library. Thanks a lot !! |
@uchuhimo |
@yashar-sb-sb You can provide default value to Kotlin data class's field, which is equivalent to use optional items. Or can you provide an example in which Konf cannot work? |
Is there a way to name properties in Kotlin data class? servers:
server:
host:
time-out: 5 and a data class:
How would one bind |
@drejc or anyone who lands here, I would use |
Newbie to Kotlin and Konf here. Is there an easier way to achieve mapping the following yaml to the Spec below:
Or does the solution involve using the jackson mapper with config.mapper? Thank you !
The text was updated successfully, but these errors were encountered: