From f2956576c13f690b5d8490c7e0784a306c1135a3 Mon Sep 17 00:00:00 2001 From: Viktoriya Nikolova Date: Thu, 19 Jun 2025 12:00:49 +0200 Subject: [PATCH 1/2] KTOR-8405 Add documentation for typed configuration in the "what's new" doc --- topics/whats-new-320.md | 48 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/topics/whats-new-320.md b/topics/whats-new-320.md index 8ea1d7ab4..e9b5b6dbd 100644 --- a/topics/whats-new-320.md +++ b/topics/whats-new-320.md @@ -11,6 +11,54 @@ Here are the highlights for this feature release: * First-class HTMX support * Suspendable module methods +## Ktor Server + +### Configuration file deserialization + +Ktor 3.2.0 introduces typed configuration loading with a new `.property()` extension on the `Application` class. You +can now deserialize structured configuration sections directly into Kotlin data classes. + +This feature simplifies how you access configuration values and significantly reduces boilerplate when working with +nested or grouped settings. + +Previously, you had to retrieve each configuration value individually. With the new `.property()` extension, you can +load the entire configuration section at once: + + + +data class DatabaseConfig( + val url: String, + val username: String, + val password: String? = null, +) + +fun Application.module() { + val databaseConfig = DatabaseConfig( + url = environment.config.property("database.url").getString(), + username = environment.config.property("database.username").getString(), + password = environment.config.property("database.password").getString(), + ) + // use configuration +} + + +@Serializable +data class DatabaseConfig( + val url: String, + val username: String, + val password: String? = null, +) + +fun Application.module() { + val databaseConfig: DatabaseConfig = property("database") + // use configuration +} + + + +This feature supports both HOCON and YAML configuration formats and uses `kotlinx.serialization` for +deserialization. + ## Ktor Client ### `SaveBodyPlugin` and `HttpRequestBuilder.skipSavingBody()` are deprecated From 3422e21bdc19d6c5eca8b2ad7f98cb3565fb5cb1 Mon Sep 17 00:00:00 2001 From: Viktoriya Nikolova Date: Fri, 20 Jun 2025 16:51:39 +0200 Subject: [PATCH 2/2] Add an example for application.yaml --- topics/whats-new-320.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/topics/whats-new-320.md b/topics/whats-new-320.md index e9b5b6dbd..c7322624c 100644 --- a/topics/whats-new-320.md +++ b/topics/whats-new-320.md @@ -21,6 +21,15 @@ can now deserialize structured configuration sections directly into Kotlin data This feature simplifies how you access configuration values and significantly reduces boilerplate when working with nested or grouped settings. +Consider the following **application.yaml** file: + +```yaml +database: + url: "$DATABASE_URL:jdbc:postgresql://localhost:5432/postgres" + username: "$DATABASE_USER:ktor_admin" + password: "$DATABASE_PASSWORD:ktor123!" +``` + Previously, you had to retrieve each configuration value individually. With the new `.property()` extension, you can load the entire configuration section at once: