https://kotlinlang.org logo
#getting-started
Title
# getting-started
j

Johann Pardanaud

10/25/2023, 11:10 AM
What's the most idiomatic way to create a configuration class? I could use a simple data class:
Copy code
data class Config(val option1: Any, val option2: Any)

Config(
    option1 = ...,
    option2 = ...,
)
But Ktor prefers to use class-like functions, with a lambda coupled to a builder receiver:
Copy code
Json {
    prettyPrint = true
    isLenient = true
}
What is recommended? Maybe the Ktor approach is more future-proof?
e

ephemient

10/25/2023, 11:21 AM
it's difficult to make ABI-compatible changes to a data class, so if that is a concern, use the builder pattern
👍 1
j

Johann Pardanaud

10/25/2023, 11:25 AM
Yep, that’s probably what I’m gonna do, thank you 🙂