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.

Serializer for Nothing not found

See original GitHub issue

Describe the bug Using Nothing in a generic type argument fails with an internal error Serializer for element of type Nothing has not been found.

To Reproduce This reproduces the problem when compiling:

import kotlinx.serialization.Serializable

@Serializable
sealed class SerializableEither<out L, out R> {

    @Serializable
    data class Left<L>(val value: L) : SerializableEither<L, Nothing>()

    @Serializable
    data class Right<R>(val value: R) : SerializableEither<Nothing, R>()
}

Full compiler error: https://pastebin.com/FP6zGrDf

Expected behavior Nothing should be serializable.

Environment

  • Kotlin version: 1.3.60
  • Library version: 0.14.0
  • Kotlin platforms: JVM
  • Gradle version: 5.6.4
  • IDE version (if bug is related to the IDE): IntelliJ IDEA 2019.2.4 (Ultimate Edition)
  • Runtime version: 11.0.4+10-b304.77 amd64
  • Linux 5.0.0-36-generic

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:6
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
fluidsoniccommented, Jul 18, 2021

I’ve just started using kotlinx-serialization in a new project and this is basically the first issue I came across, with a compiler error that’s not very helpful (location: “File is unknown”).

Having a default serializer for Nothing would avoid that, wouldn’t it?

3reactions
sandwwraithcommented, Dec 3, 2019

So it would be basically like this:

object NotSerializable : KSerializer<Any> {
    override val descriptor: SerialDescriptor = SerialClassDescImpl( "kotlin.Any") 
    override fun deserialize(decoder: Decoder): Any = throw SerializationException("Not serializable")
    override fun serialize(encoder: Encoder, obj: Any) = throw SerializationException("Not serializable")
}

Such serializer can be applied for types in generic arguments (data class Left<L>(val value: L) : SerializableEither<L, @Serializable(NotSerializable::class) Nothing>()).

It even can be a default serializer for Nothing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kotlin - Cannot serialize polymorphic classes. No serializer ...
SerializationException : Serializer for class 'Project' is not found. Mark the class as @Serializable or provide the serializer explicitly ...
Read more >
Serializer in serde::ser - Rust - Docs.rs
Enables serializers to serialize byte slices more compactly or more efficiently than other types of slices. If no efficient implementation is available, ...
Read more >
Tutorial 1: Serialization - Django REST framework
Tutorial 1: Serialization. Introduction. This tutorial will cover creating a simple pastebin code highlighting Web API. Along the way it will introduce the ......
Read more >
Serialization Tutorial - GitHub Pages
An alternative is to serialize nothing to the BSON document when the ... Normally, if no matching field or property is found, an...
Read more >
Source code for aiocache.serializers
getLogger(__file__) try: import ujson as json except ImportError: logger.warning("ujson module not found, using json") import json try: import msgpack ...
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