Status Update
Comments
jb...@google.com <jb...@google.com>
cl...@google.com <cl...@google.com> #2
Upon investigation, this issue applies to custom types that the user does not own. In this case, LocalDate is a third-party type owned by Java.
This bug happens because we match an argument to the custom NavType by matching their serializer. Generally when you apply the @Serializable / @Serializable(with = ...)
to your custom type, kotlinx.serialization
library generates a serializer and attaches it the MyCustomType.Companion
. However, since you don't own LocalDate
, serialization library cannot modify its source code and thus the serializer is not attached to it.
This leads to the missing serializer
exception when we attempt to the get the serializer for LocalDate
- it's not directly associated to this type.
There is a temporary work around for third-party types by wrapping it with your own custom type
@Serializable
value class MyLocalDate(val date: LocalDate)
@Serializable
data class List(localDate: MyLocalDate)
Though ideally this workaround should not be required.
pr...@google.com <pr...@google.com> #3
ap...@google.com <ap...@google.com> #4
Branch: androidx-main
commit 5320d9d93909268f9f47bd0840ae2f3da228a5ab
Author: Clara Fok <clarafok@google.com>
Date: Mon Jun 17 16:08:28 2024
Improve error message on field-declared serializers
Safe Args implementation currently does not support serializers declared on a class field. This applies regardless of whether the field Type is a custom type or third-party type.
Improve error messaging to clarify that this is an unsupported feature as of 2.8.0.
This issue is expected to be addressed in navigation 2.9.
Test: ./gradlew navigation:navigation-common:test
Bug: 341319151
Relnote: "Improve error message for customer serializers declared directly on class fields via @Serializable(with =...) to clarify that this is currently an unsupported feature."
Change-Id: I052b0e6a34c7e38520723e7c00a920dc7abe4eb7
M navigation/navigation-common/src/main/java/androidx/navigation/serialization/NavTypeConverter.kt
M navigation/navigation-common/src/test/java/androidx/navigation/serialization/NavTypeConverterTest.kt
jb...@google.com <jb...@google.com> #5
We reviewed the issue as laid out in @Contextual
annotation does not provide quite enough information for the library to determine the type and our current other option would lean into the use of SerialName
which we opted against supporting earlier for a number of reasons. With that conclusion, and since there is a known work around available, we have decided to continue to investigate this and look at possible options in the Navigation 2.9.0 release.
For now, we will improve the error message around this use case to ensure developers are aware of the current status. Follow
pr...@google.com <pr...@google.com> #6
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.navigation:navigation-common:2.8.0-beta04
dr...@gmail.com <dr...@gmail.com> #7
workaround from
ar...@physitrack.com <ar...@physitrack.com> #9
Is there any official sample on how to use wrapping into value class
to workaround this issue? I also couldn't find a way to make it work.
ap...@google.com <ap...@google.com> #10
Project: platform/frameworks/support
Branch: androidx-main
Author: Clara Fok <
Link:
Add nav sample for serializable third party types
Expand for full commit details
Add nav sample for serializable third party types
Sample to show workaround for b/341319151
Test: manual testing
Bug: 341319151
Bug: 348468840
Change-Id: I8c5553029b827440e55c0ecd0ceeb4ffc9957473
Files:
- M
navigation/navigation-compose/samples/src/main/java/androidx/navigation/compose/samples/NavigationSamples.kt
Hash: 16eb5c9060a623a5977f56f10ab782d5b27d6765
Date: Thu Oct 17 18:34:45 2024
pr...@google.com <pr...@google.com> #12
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.navigation:navigation-compose:2.9.0-alpha02
Description
Component used: Navigation
Version used: androidx.navigation:navigation-compose:2.8.0-beta01
Devices/Android versions reproduced on: emulator, API 34
I have a java.time.LocalDate in the navigation object; I want to implement a custom nav type. Even though, the navigation lib tries to obtain a KotlinX's serializer and crashes.