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.

@Serializable objects cause compilation errors

See original GitHub issue

Hi when i run this code i get java.lang.NoSuchFieldError: Companion exception.

fun main() {
    val a = A // Throws java.lang.NoSuchFieldError: Companion
}

@Serializable
object A

@Serializer(forClass = A::class)
object ASerializer : KSerializer<A> {

    override val descriptor = SerialClassDescImpl("ASerializer")

    override fun serialize(encoder: Encoder, obj: A) = encoder.encodeString(obj::class.qualifiedName!!)

    override fun deserialize(decoder: Decoder): A = decoder.decodeString().run { A }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
sandwwraithcommented, Nov 28, 2019

@Serializable object is supported starting from Kotlin 1.3.60/kotlinx.serialization 0.14.0

0reactions
pauliusrumcommented, Mar 15, 2019

@pdvrieze I agree with what you are saying but this is a very early stage of the project so it will do for now. In the future I will have to change it to be more portable with a custom serializer for sealed class Error.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - Compile error on Serializable when ...
I am getting compilation error when compiling a Jdk8 codebase with OpenJdk11 on Serializable class with error : The type java.io.
Read more >
Class Serialization Traits
Compile Time Warnings and Errors. Some serialization traits can conflict with other ones. Sometimes these conflicts will result in erroneous behavior (E.G. ...
Read more >
Spark Error Task Not Serializable | The Startup
Cause of Task Not Serializable exception in Spark. Discusses functional interfaces in Java/Scala, closures, ObjectOutputStream.writeObject, Java 7 vs Java ...
Read more >
Serialization in Java - Examples and Vulnerabilities
This article discusses serialization vulnerabilities in Java, factors that cause exposure, and strategies to prevent them. What is Serialization ...
Read more >
Java Object Serialization Specification: 1 - System ...
Objects to be saved in the stream may support either the Serializable or the Externalizable interface. For Java TM objects, the serialized form...
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