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

How to deserialize JSON with dynamic object?

I have a simple json, but the containing field has dynamic object. For instance, json can look like { "fixedField1": "value1", "dynamicField1": { "f1": "abc", "f2": 123 } } or { "fixedField1": "value2", …
sidgate
  • 14,650
  • 11
  • 68
  • 119
1
vote
1 answer

Obtaining serializer from KClass is not available on native due to the lack of reflection

Description I'm using Kotlinx serialization library in a multiplatform library for iOS and Android to handle HTTP requests. But I have this message when I'm using my request function on iOS, is there a workaround ? What line in my function is…
Alan
  • 1,264
  • 1
  • 11
  • 21
1
vote
1 answer

migrating from Python JSON to Kotlin JVM JSON

I have existing Python programs which use import json and use json.load() json.loads() method to read the json and present it in code in easy to use accessible dictionary. I use python json[name][] = value constructs to reference the json data…
Acid Rider
  • 1,557
  • 3
  • 17
  • 25
1
vote
1 answer

Expected '[, kind: POLYMORPHIC'

I am trying to get custom serializing to work with kotlinx.serialization like this reduced example: @Serializable open class KdfParams { var dklen: Int = 0 var salt: String? = null @Serializer(forClass = KdfParams::class) companion…
ligi
  • 39,001
  • 44
  • 144
  • 244
0
votes
0 answers

Kotlinx Serialisation for nested class

I am working on Kotlinx Serialisation and there is an error in serialising nested class. This class is not serializable automatically because it has primary constructor parameters that are not properties The workaround is to go with polymorphism…
0
votes
0 answers

Serialization of any Kotlin @Serializable type

I have the following Kotlin code using Kotlin Serialization: package com.renault.rclib import kotlinx.serialization.Serializable import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json abstract class Processor
wujek
  • 10,112
  • 12
  • 52
  • 88
0
votes
0 answers

Android .I don't get data when using kotlinx serialization

When creating the application, I had difficulties with kotlinx serialization. I wrote the code based on the article: https://vtsen.hashnode.dev/simple-rest-api-android-app-in-kotlin-various-http-client-library-implementations…
0
votes
0 answers

Kotlin serialization: Implementing a custom encoder for digest which ignore a val in an interface

I'm making my own implementation of AbstractEncoder for a goal of digest, trying to ignore specific interface when implementing Encoder. I have an interface: interface HasId { val Id: Int } and various classes implementing…
A-_-S
  • 680
  • 5
  • 21
0
votes
1 answer

Serialize (uselessly) nested JSON to Kotlin data class

I have two Kotlin data classes, Song and Thumbnail, and I am facing a lot of nesting that I want to avoid. Here are the class definitions: data class Song( val title: String, val year: Int, val watchId: String, val thumbnails:…
0
votes
1 answer

Kotlinx.serialization library is just deserializing one value (the first) from a data class

I'm trying to deserialize a data class to be sent through a WebSocket with the Kotlinx.serialization library using Ktor, but I'm having some issues, the serializer just deserializes the first value of the data class. I'm using Kmongo for the…
0
votes
0 answers

How to write generic type serializer in Kotlin?

I write some kind of Any type serializer, but I get issue with converting data classes to json. And I get this kind of error: Caused by: kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 3: Encountered an…
0
votes
1 answer

How to use kotlinx serialization with Spring AMQP?

It seems that spring AMQP has built-in MessageConverter support for Jackson with the Jackson2JsonMessageConverter class, but is there an equivalent for the kotlinx serialization lib, or would it be necessary to write a custom message converter for…
0
votes
0 answers

How does Kotlinx.Serialization use encodeToJsonElement() function to serialize Any type?

I'm trying to serialize an object into json format using encodeToJsonElement. import kotlinx.serialization.ContextualSerializer import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.InternalSerializationApi import…
SageJustus
  • 631
  • 3
  • 9
0
votes
1 answer

how to serialize JSON with a dynamically changing key?

I have Json: { "216632": { "prefiks": "", "anyid": "0", "tel": "123456789", "firma": "Brand", "fio": "Name", "comment": "Text", "address": "Address", "kv": "99", "adres_id": "11130", "gps": "99.666666…
0
votes
0 answers

Kotlinx Serializer for List instead of just T at Serializable annotation of field

So I have this class to for Json deserialization: @Serializable data class NetworkUser( @SerialName("id") val id: Long, ... @Serializable(RoleSerializer::class) @SerialName("role") val role: List ) Serializer for…
user924
  • 8,146
  • 7
  • 57
  • 139