Questions tagged [kotlinx.serialization]

Kotlin serialization generated code to serialize objects without reflection only by marking a class with @Serializable annotation.

Kotlin serialization consists of a compiler plugin, which automatically produces visitor code for classes, and runtime library, which uses generated code to serialize objects without reflection.

  • Supports Kotlin classes marked as @Serializable and standard collections.
  • Supports JSON, CBOR, and Protobuf formats out-of-the-box.
  • The same code works on Kotlin/JVM, Kotlin/JS, and Kotlin/Native
262 questions
1
vote
1 answer

Obtaining serializer for a class in kotlinx.serialization

Assume that C is a serializable class: @Serializable class C I have at least four ways of obtaining serializer for this class. Companion(?) function. Actually IDEA doesn't let me to go to declaration, so I assume it's a kind of synthetic…
1
vote
3 answers

How to serialize a generic class with kontlinx.serialization?

I have followed a tutorial to create a custom serialization for my generic class. But I am still stacked with error: SerializationException: Serializer for class 'ApiResponse' is not found. Mark the class as @Serializable or provide the…
P. Savrov
  • 1,064
  • 4
  • 17
  • 29
1
vote
2 answers

NoClassDefFoundError kotlinx serialization

I have a kotlin multiplatform project and I need to serialize a class. I have included the following dependency in my commonMain and androidMain and iosMain respectively in my multiplatform gradle file: //commonMain implementation…
1
vote
1 answer

Kotlinx.Serialization: Exclude object from serialization if all inner properties are also excluded

I’m trying to implement functionality that excludes the whole object from the serialization if all inner objects are excluded. For example when I want to serialize this data class to json data class Car(val engine: Engine? = null, val size: Size? =…
user2875643
  • 93
  • 2
  • 3
1
vote
1 answer

Getting kotlinx serialization working in multiplatform project

I'm taking Kotlin seriazliation for a test drive in a multiplatform project in Kotlin 1.4-M2, following the tutorial on github, but i'm not getting the serialization bit to compile. This is my build.gradle.kts plugins { val kotlinVersion =…
1
vote
1 answer

kotlinx de/serialization sealed class/enum

Writing chat app using kotlin, historically from nodejs I have websocket json objects in/output format: {"action": "join:chatroom", "payload", "chatroom-name"} {"action": "leave:chatroom", "payload", "chatroom-name"} {"action": "message", "payload",…
Roman Vasilyev
  • 149
  • 4
  • 12
1
vote
0 answers

Using kotlinx.serialization library with Bazel's rules_kotlin

How does one go about using the kotlinx.serialization library with Bazel's rules_kotlin? This is what I've tried: java_plugin( name = "grrr_plugin", processor_class =…
mancini0
  • 4,285
  • 1
  • 29
  • 31
1
vote
1 answer

@SerialInfo - How to manage user-defined serial annotations with Kotlinx serialization?

Kotlinx serialization documentation According to Kotlinx.serialization user-defined annotations doc: "Inside a process of serialization/deserialization, your own annotation class are available in SerialDescriptor object" : override fun…
1
vote
2 answers

Delegate issue with Mongo and Kotlin

I've recently been using Kmongo library and Kotlin together however I've made an issue on Kmongo but I'm unsure it is related to the library. I'm trying to persist my data onto my mongo database (version 4.2.2) @Serializable data class Person(val…
1
vote
1 answer

How to work with KotlinX serialization for ArrayList and Date types with Algolia

I am trying to use the kotlinx serialization with Algolia for types ArrayList and Date but I cannot figure out the serialization technique. Any pointers because I have resorted to the manual way that is not recommended by Algolia.
1
vote
0 answers

Kotlinx.serialization not working on androidTest

Have Ktor setup and working fine in my project. When running androidTest ("instrumentation tests") I get a NoSuchMethodError for Json.nonstrict.parse()code running in the tests. This is code in the test apk, not in the…
1
vote
0 answers

Ktor: JsonDecodingException on valid JSON

The exception below is thrown after this code. Interestingly it works while debugging and stepping through the code. The exception is thrown on the last line. Kotlin 1.3.60 Ktor 1.2.6 kotlinx.serialization 0.14.0 } catch (throwable: Throwable)…
1
vote
1 answer

How to use @SerializedName in Kotlin Multiplatform project?

I am using Kotlin multiplatform. I am getting object name in Json response. I want to map object name with other name. So I found to use @SerializedName. But it's not working. It says Unresolved reference: SerializedName.
Rajesh Maurya
  • 3,026
  • 4
  • 19
  • 37
1
vote
1 answer

Data class with ByteArray in kotlin

I created a Data class in Kotlin that contains an image as a ByteArray. When I build I have the following error: Error:Kotlin: [Internal Error] java.lang.IllegalStateException: Backend Internal error: Exception during code generation Cause: An…
1
vote
1 answer

How to iterate a JsonElement with unknown keys on Kotlin using kotlinx?

I'm new on Kotlin and I'm trying parse a Json file to take your values. The first problem is that I don't know the keys and the second problem is that I don't know use Kotlin perfectely. Let me explain the case. This is a Json format that I getting…
Augusto
  • 3,825
  • 9
  • 45
  • 93