I want to open a fragment using navigation component and deeplink.
val serializedUser = Gson().toJson(user)
findNavController().navigate(Uri.parse("myapp://?user=${serializedUser}"))
but in destination fragment sometimes argument is not complete.
val serializedUser = arguments?.getString("user")
val post = Gson().fromJson(serializedUser, User::class.java)
and getting this error:
com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 1156 path $.text
if I log serializedUser
in destination fragment this not complete and some character in end of it is not exist, while in first fragment it is complete.
serialized model is a long string but seems length of it is not related for this problem. because some longer serialized model working.
this problem is occur only if using navigation component deeplink.
Uri.parse(String)
parses an encoded URI string, however you are not encoding serializedUser
.
To solve this you should use Uri.fromParts(...)
or the Uri.Builder
class instead which does not require you to encode serializedUser
.