How do I pass kotlinx @Serializable object as a back result in compose multiplatform
09:44 25 Jul 2025

According to release notes here SavedState now supprots kotlix.serialization. So I'm trying to lavarage it for navigation. It works as expected for nav args but when I'm trying to pas it as a result to the previous BackStackEntry it either crashes or does nothing.

If I call

navController.previousBackStackEntry?.savedStateHandle?.set("RESULT", brand)

It crashes with

java.lang.IllegalArgumentException: Can't put value with type class com.....brands.data.dto.BrandDto into saved state
at androidx.lifecycle.SavedStateHandle.set(SavedStateHandle.android.kt:151)

If I'm using

private var result by resultHandle.saved(RESULT_BRAND_EDIT) { brand }
...
result = brand
navController.popBackStack()

and

private val brand by savedStateHandle.saved(RESULT_BRAND_EDIT) { BrandDto(name = "") }
...
product.brand = brand

When I read this value (when the screen onResume is triggered after navigation back), it returns the default value for brand, not the one I put in the code above.

So I'm wondering if is a problem with the framework or am I doing something wrong? Is there any example of working code for such scenario?

android kotlin android-jetpack-compose multiplatform