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
0
votes
1 answer

polymorphic kotlinx serialization fails on object after obfuscation

i have a polymorphic type that is implemented by objects and classes. sealed interface Base @Serializable @SerialName("Sub") class Sub(...) : Base @Serializable @SerialName("Obj") object Obj : Base i use this type with…
Noam Freeman
  • 143
  • 1
  • 8
0
votes
2 answers

Null or Empty Object parsing in Kotlinx.serialization

How to parse both types of responses: { "x" : "some_string" } and { "x" : { } } Into a data class that looks like: @Serializable data class SomeClass { @SerialName("x") val x : String? }
0
votes
1 answer

NullPointerException at KotlinxSerializer when GET returns null instead of a List

Using Ktor I'm fetching a List like this, which in some cases returns null. override suspend fun getDevices(accessToken: String): List? { return client.get { url(path = "/devices") header("Authorization", "Bearer…
H.Step
  • 95
  • 1
  • 10
0
votes
1 answer

Kotlinx serialization parsing enum ignore unknown value

I've a json which looks like: [ { "object": [ { "enumValue1": "value1", "value2": 1 } ], }, { "object2": [ { "enumValue1": "value2", "value2": 2 } ], }, { …
JohnDoe
  • 1
  • 2
0
votes
1 answer

Kotlin Serialiazation with polymorphism MissingFieldException

I have these Model classes @Serializable open class BaseModel( var network: String? = null, var type: String? = null, var createdOn: String? = null, var updatedOn: String? = null, var name: String? = null, var imageUrl:…
Burhan Khanzada
  • 945
  • 9
  • 27
0
votes
0 answers

ktor-client : how to serialize a post body as a specific type

With ktor client, I've got a non-serializable object derived from a serializable object like so: @Serializable @SerialName("login-request") open class LoginRequest ( open val email : String = "", open val password : String = "" ) :…
FatalCatharsis
  • 3,407
  • 5
  • 44
  • 74
0
votes
1 answer

Seem like i can't handle response from mongodb when using hyphen in field name

I didn't see any recommendation about using hyphen in field name at all Even with @serialName it still didn't work @SerialName("created-date") val created_date: String, but It worked fine with underscore (now i'm using it) The reason i used it in…
adwardwo1f
  • 817
  • 6
  • 18
0
votes
0 answers

Spring-boot is not recognising Koltin serializers written for third party libraries

The external class I am using: https://github.com/arrow-kt/arrow/blob/5e0db6b7aaeb1ac99ecbfff74f03cce28e234391/arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt#L725 Either Sealed class from Arrow.Core library. This is my custom…
0
votes
0 answers

Error: Incompatible types: Class cannot be converted to Class>

I am using kotinx.serialization library And Getting This error everywhere I specified a custom serializer using @Serializable annotation ! Error : error: incompatible types: Class cannot be converted to Class
0
votes
3 answers

What should be the Kotlin class to represent a json with array of classes

Given the following JSON: { "from": 1, "to": 3, "results": [ { "item": { "status": "SUCCESS", "statusMessage": "", "requestId": "1" } }, { "item": { "status":…
0
votes
1 answer

java.lang.NoClassDefFoundError: on Android 6

App is working fine on Nexus6P running android 9. I am trying to run application on Nexus 5 (Android 6) but getting the following error: Caused by: java.lang.NoClassDefFoundError:…
Mustansar Saeed
  • 2,730
  • 2
  • 22
  • 46
0
votes
0 answers

kotlinx serialization. Deserialize generic parameter trouble

I am migrating my project serialization client from GSON to KotlinxSerialization and Faced a problem: All responses from API inherit an abstraction class for example: abstract class BaseResponse ( val type: String? = null, val payload: T? =…
0
votes
1 answer

kotlinx.serialization question for specific case

I have following data class @Serializable data class TestClass( val id: Int, val content: String) and following possible JSONs {"id" = "1", "content": "1" } {"id" = "2", "content": {"subcontent1": "subvalue1"} } {"id" = "3", "content":…
Ivan
  • 340
  • 3
  • 14
0
votes
0 answers

How do I build a SerialDescriptor for a class when a field has a different serialization mechanism?

I have this class (simplified) @Serializable(with = MetaAny.Serializr::class) class MetaAny constructor( val obj: Any, val meta: String? = null) { object Serializr: KSerializer { override val descriptor: SerialDescriptor = …
Travis Well
  • 947
  • 10
  • 32
0
votes
1 answer

kotlinx.serialization Json config: use singleton or build every time?

I'm building a Kotlin server application. I know that I will need a specific Json configuration such as Json { ignoreUnknownKeys = true } throughout. My question is whether it makes more sense to declare a top-level var (or maybe an object with the…
ExactaBox
  • 3,235
  • 16
  • 27