Hey, I’m using compose navigation with a custom na...
# compose
k
Hey, I’m using compose navigation with a custom nav type, where I subclass NavType to serialize/deserialize my type. I noticed that if a url value is stored in my type’s property, I get an error
Navigation destination that matches request (…) cannot be found in the navigation graph
. I found out that uri decoding the value in overridden
serializeAsValue
method makes it work, but I cannot find it anywhere mentioned it documentation. Is this the right approach or is there something I’m missing?
i
The docs: https://developer.android.com/guide/navigation/design/kotlin-dsl#custom-types
Copy code
override fun serializeAsValue(value: SearchParameters): String {
  // Serialized values must always be Uri encoded
  return Uri.encode(Json.encodeToString(value))
}
1
k
Copy code
// Serialized values must always be Uri encoded
ah, gotcha, so uri encoding it was a right thing to do
i
If you search for
Uri.encode
you'll find a couple of threads where we've talked about this before too
You'll note that
StringType
does this automatically for you if you use a
String
type in your class