Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@NavTypeSerializer is not visible when defined in another module #265

Closed
Nek-12 opened this issue Oct 17, 2022 · 5 comments
Closed

@NavTypeSerializer is not visible when defined in another module #265

Nek-12 opened this issue Oct 17, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@Nek-12
Copy link

Nek-12 commented Oct 17, 2022

I'm struggling with the architecture of passing an UUID as a destination parameter.
I'm using an UUID as an argument, and the compiler wants to see a serializer for that type, but I've defined it in my common-navigation module which I include into my current module, and it still does not compile.
I'm now forced to copy and paste the serializer into each of these modules. The implementation of the serializer object simply delegates to an actual UUIDSerializer, which I obviously already have in my project, but it's defined in another module.

Desired behavior:
I want to annotate a destination parameter with something like @SerializeWith(UUIDSerializer::class) just like it's done in the kotlinx.serialization library.

That would solve the visibility problem (which I assume you won't be able to fix), the duplication problem, architecture, and also allow for different serializers for each composable / parameter, unlike it's done now (what if I want to serialize something in different ways in 1 module?)

@Nek-12
Copy link
Author

Nek-12 commented Oct 17, 2022

Okay, this is getting more complex by the minute...

UUID obviously implements java.io.Serializable. Documentation says custom serializers shouldn't be needed for these types, ok, but I get

[ksp] com.ramcosta.composedestinations.codegen.commons.IllegalDestinationsSetup: Composable 'OngoingRitualScreen', arg name= 'ritualId': deep links cannot contain mandatory navigation types of custom type unless you definea custom serializer with @NavTypeSerializer. This lets you control how the custom type class is defined in the string route.

Defining a duplicate of the serializer as

@NavTypeSerializer
object UUIDNavTypeSerializer : DestinationsNavTypeSerializer<Uuid> by UUIDNavTypeSerializer // from my nav module

now leads to the following:

[ksp] java.lang.ClassCastException: class com.google.devtools.ksp.symbol.impl.binary.KSTypeAliasDescriptorImpl cannot be cast to class com.google.devtools.ksp.symbol.KSClassDeclaration (com.google.devtools.ksp.symbol.impl.binary.KSTypeAliasDescriptorImpl and com.google.devtools.ksp.symbol.KSClassDeclaration are in unnamed module of loader java.net.URLClassLoader @449bf44b)
	at com.ramcosta.composedestinations.ksp.processors.Processor$getNavTypeSerializers$1.invoke(Processor.kt:85)
	at com.ramcosta.composedestinations.ksp.processors.Processor$getNavTypeSerializers$1.invoke(Processor.kt:65)
	at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210)
	at kotlin.sequences.SequencesKt___SequencesKt.toCollection(_Sequences.kt:787)
	at kotlin.sequences.SequencesKt___SequencesKt.toMutableList(_Sequences.kt:817)
	at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:808)
	at com.ramcosta.composedestinations.ksp.processors.Processor.getNavTypeSerializers(Processor.kt:92)
	at com.ramcosta.composedestinations.ksp.processors.Processor.process(Processor.kt:30)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$6$1.invoke(KotlinSymbolProcessingExtension.kt:287)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension$doAnalysis$6$1.invoke(KotlinSymbolProcessingExtension.kt:285)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.handleException(KotlinSymbolProcessingExtension.kt:390)
	at com.google.devtools.ksp.AbstractKotlinSymbolProcessingExtension.doAnalysis(KotlinSymbolProcessingExtension.kt:285)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:124)
	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:100)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:265)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:53)
	at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:256)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:99)
	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:58)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:158)
	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:53)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:99)
	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:47)
	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:101)
	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1645)
	at jdk.internal.reflect.GeneratedMethodAccessor106.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:360)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:712)
	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

This is because I'm using a multiplatform uuid where Uuid is defined as

public actual typealias Uuid = java.util.UUID

If I explicitly change the serializer to java.util.UUID it does not produce any error.

@raamcosta
Copy link
Owner

Hi @Nek-12! Thanks for pushing the boundaries with this library ahah 😄

I get the second error, and it's an easy fix. As for the initial request, I'll have to check, but the proposed solution does sound like something I could do 👍

Regarding the error, you're getting with serializable. This is basically here because since your screen has deep links which must be able to take this argument type, you need to specify how exactly your UUID will be represented in the route, otherwise, if we use the default serializable nav type, it will look like base64 random string and on deep links, we need to have more visibility I believe.

So if you weren't using deep links with mandatory nav arguments of these types (Serializable/Parcelable) then you wouldn't need any NavTypeSerializer.

@raamcosta raamcosta added the enhancement New feature or request label Oct 17, 2022
@raamcosta
Copy link
Owner

@Nek-12 the second error should be fixed with newest version of the library.

@Nek-12
Copy link
Author

Nek-12 commented Nov 1, 2022

This also seems to be a duplicate of #173

@raamcosta
Copy link
Owner

Correct! Thanks @Nek-12 👍

closing this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants