question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compiler Exception when defining a serializer for a data class in another gradle project

See original GitHub issue

I 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:open
  • Created 4 years ago
  • Reactions:12
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
igrcommented, Apr 21, 2022

Still Kotlin 1.6.20 and serialization 1.3.2.

(do you see the pattern here?😃

1reaction
mqueiroz1995commented, Feb 26, 2021

Still happens with kotlin 1.4.30 and serialization 1.1.0.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found