Status Update
Comments
p....@squaregps.com <p....@squaregps.com> #2
Hi. We ran into something like this. I'd really like some support
p....@squaregps.com <p....@squaregps.com> #4
We decided to use the solution from the comment (via @Contextual) 👀
I would like to note this point in the documentation, if it is not noted.
da...@ext.otpbank.hu <da...@ext.otpbank.hu> #5
da...@gmail.com <da...@gmail.com> #6
Curious about what is the recommendation for:
@Serializable
data class MyDestination(val id: UUID) {
companion object {
val typeMap = mapOf(
typeOf<UUID>() to NavType.SerializableType(UUID::class.java),
)
fun from(savedStateHandle: SavedStateHandle) = savedStateHandle.toRoute<MyDestination>(typeMap)
}
}
The following compilation error is present for UUID
:
Serializer has not been found for type 'UUID'. To use context serializer as fallback, explicitly annotate type or property with @Contextual
Furthermore, if I set a custom Serializer
for the Class of MyDestination
by @Serializable(MySerializer::class)
, then I also get the following error:
Custom serializers declared directly on a class field via @Serializable(with = ...) is currently not supported by safe args for both custom types and third-party types. Please use @Serializable or @Serializable(with = ...) on the class or object declaration.
Version 2.8.0-beta05
.
ja...@gmail.com <ja...@gmail.com> #7
My usecase is following:
@Serializable
data class DialogActivityDayHistory(
val activityId: Long,
@Serializable(LocalDateSerializer::class)
val date: LocalDate
)
dr...@gmail.com <dr...@gmail.com> #8
Even in the latest version 2.8.0
,
pe...@gmail.com <pe...@gmail.com> #9
Expanding on whole thread or #7 for simple example.
What bothers me, is that when you define a custom @Serializable
class and you try to pass it between destination routes, it will fail, because there is no custom NavType
serializer defined. If custom data type is serializable, I would expect it to get serialized and de-serialized between destinations.
ap...@google.com <ap...@google.com> #11
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
Description
Currently if you attempt to use
@Serializable(with = ...)
on a class field, Navigation will fail with a message indicating that it is not supported.Ideally, Navigation would support this use case and would not require a workaround (see this issue for context). We should explore the options available to fix this issue internally in future Navigation versions.