Reham Galal
02/05/2025, 9:23 AMAleksei Tirman [JB]
02/05/2025, 9:24 AMReham Galal
02/05/2025, 9:25 AMMoussa
02/05/2025, 9:31 AM@Serializable
data class DTO(val name: String? = null)
• Add Default Values
@Serializable
data class DTO(val name: String = "default-name")
• isLenient to true
In your Json configuration from kotlinx.serlization inside ktor you can set isLenient to trueReham Galal
02/05/2025, 9:32 AMMoussa
02/05/2025, 9:35 AMignoreUnknownKeys to ignore any keys that are extra or you don't want to add to your model
install(ContentNegotiation) {
json(Json {
isLenient = true
ignoreUnknownKeys = true // Ignore unknown keys in JSON (optional)
})
}
example
{
"username": "moussa147",
"pass": "123456",
"hello": "world"
}
@Serializable
data class Model(val username: String, val pass: String)
When you use ignoreUnknownKeys it will ignore the hello in the JSONReham Galal
02/05/2025, 9:37 AM