Compiler Exception when defining a serializer for a data class in another gradle project
See original GitHub issueI am trying to define an external serializer for a data class (Data) which is defined in another gradle module (subproject) and the result is the following exception.
Caused by: java.lang.IllegalStateException: Class Data have constructor parameters which are not properties and therefore it is not serializable automatically
at org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializerCodegen.checkSerializability(SerializerCodegen.kt:38)
at org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializerCodegen.generateSerializableClassPropertyIfNeeded(SerializerCodegen.kt:106)
at org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializerCodegen.generate(SerializerCodegen.kt:44)
at org.jetbrains.kotlinx.serialization.compiler.backend.jvm.SerializerCodegenImpl$Companion.generateSerializerExtensions(SerializerCodegenImpl.kt:49)
at org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationCodegenExtension.generateClassSyntheticParts(SerializationCodegenExtension.kt:30)
at org.jetbrains.kotlin.codegen.ImplementationBodyCodegen.generateSyntheticPartsAfterBody(ImplementationBodyCodegen.java:438)
at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:132)
at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:302)
at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:286)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateClassesAndObjectsInFile(PackageCodegenImpl.java:118)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateFile(PackageCodegenImpl.java:137)
at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:68)
... 44 more
It works if the data class is defined in the same gradle module as the serializer.
To Reproduce
Check out https://github.com/mdietrichstein/bug_repro_kotlinx.serialization_gradle_multiproject_ext_serializer and run ./gradlew clean test
Expected behavior The compiler executes successfully
Environment
- Kotlin version: 1.3.31 and 1.3.41
- Library version: 0.11.0 and 0.11.1
- Kotlin platforms: Android
- Gradle version: 5.4.1
- Other relevant context: Ubuntu 18.04 and MacOSX
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:9 (1 by maintainers)
Top Results From Across the Web
kotlin - Serializer for class '...' is not found. Mark the class as ...
first: I needed to add the plugin in the gradle at the app and project level, ... Keep `Companion` object fields of serializable...
Read more >Serialization | Kotlin
First, make a class serializable by annotating it with @Serializable . import kotlinx.serialization.Serializable @Serializable data class Data( ...
Read more >Serialization with Jackson - Documentation - Akka
This section describes how to use the Jackson serializer for application specific messages and persistent events and snapshots. Jackson has support for both ......
Read more >Spring Native documentation
Add the native build tools plugin. GraalVM provides Gradle and Maven plugins to invoke the native image compiler from your build. The following ......
Read more >Groovy Language Documentation
Static inner classes; Anonymous Inner Classes; Creating Instances of ... can be stored in variables, assigned into fields, just like any other data...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Still Kotlin 1.6.20 and serialization 1.3.2.
(do you see the pattern here?😃
Still happens with kotlin 1.4.30 and serialization 1.1.0.