Questions tagged [kotlinx]

44 questions
17
votes
2 answers

kotlinx-serialization: Polymorphic serializer was not found for missing class discriminator ('null')

I am trying to serialize a json, but its throwing JsonDecodingException. Check the code: SerializationTestCase.kt: import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromString import…
Chintan Soni
  • 24,761
  • 25
  • 106
  • 174
7
votes
1 answer

Unresolved Reference Kotlinx in IntellijIdea. Even after adding the library

I just wanted to taste Kotlin coroutines. Unfortunately, I haven't been able to use the library kotlinx in IntelliJ. I have downloaded the library through Maven. Tried invalidating caches. Rebuilt project. Tried using it in a fresh project. Even…
nilTheDev
  • 380
  • 3
  • 14
6
votes
3 answers

Kotlinx.Serialization deserializing dates

I'm having a hard time finding documentation on how to deserialize date fields. How do i achieve this? Most solutions i found on SO don't work or they use classes that are no longer available @Serializable data class Dashboard( val someNumber:…
aryaxt
  • 76,198
  • 92
  • 293
  • 442
5
votes
1 answer

android kotlin multiplatform kotlinx.serialization works on debug but does not work on release version

We are making our next project in the company with kotlin multiplatform. Everything worked fine until I tried to create a release version for android to beta test. I got this error in release versions while everything works fine in…
4
votes
3 answers

How do I create the onClick function for a button with Kotlinx.html?

I am using Kotlin's html library kotlinx.html for dynamic html building. I want to create a button which triggers a function when clicked. This is my current code: class TempStackOverflow(): Template { var counter: Int = 1 …
Lekkkim
  • 43
  • 3
4
votes
4 answers

Why do I get ‘does not implement abstract member’ warning while using kotlinx.android.parcel.Parcelize?

I am getting this error while trying to read the bundle from another fragment where I am sending the NewVehicle object. Error : Class 'NewVehicle' is not abstract and does not implement abstract member public abstract fun describeContents(): Int…
Sweta Jain
  • 3,248
  • 6
  • 30
  • 50
3
votes
2 answers

How do I provide a page template in kotlinx-html?

I would like to generate a bunch of HTML files with kotlinx-html and I want to start each file with the same template. I would like to have a function for the base structure and provide a lamda to this function for the specific content like so (non…
ChrLipp
  • 15,526
  • 10
  • 75
  • 107
3
votes
1 answer

Polymorphic kotlinx serialization when type is integer, not string

I am trying to consume and emit JSON which contains a polymorphic list of items. The problem is: the items contain type key with integer values (not strings). The API endpoint produces and expects JSON similar to this: { "startTime":…
Bobrovsky
  • 13,789
  • 19
  • 80
  • 130
3
votes
0 answers

HTML in Jetpack Compose Text

I tried to enable HTML strings, especially with links e.g.: "We are a team of professionals working hard to provide free learning content." I used it like explained here by Akram Hussain: val body = "We are a
3
votes
1 answer

kotlinx serialization — best way to do polymorphic child deserialization

I have a Json input like: { "type": "type_1", "data": { // ... } } data field can vary depending on type. So, I need a deserializer, that looks on type (enum) and deserializes data respectively (for instance, for type_1 value it's…
artem
  • 16,382
  • 34
  • 113
  • 189
3
votes
2 answers

Custom KotlinX Serializer for List class

I want to make a custom List serializer that will parse invalid json arrays safely. Example: list of Int [1, "invalid_int", 2] should be parsed as [1, 2]. I've made a serializer and added it to Json provider, but serialization keeps failing after…
Wackaloon
  • 2,285
  • 1
  • 16
  • 33
3
votes
1 answer

can I use kotlinx serializer with multiple sealed class levels as parents and a nested invocation?

I am trying to use kotlinx @Serializable and Ive faced this issue: I have the following classes: @Serializable sealed class GrandParent a second one: @Serializable sealed class Parent() : GrandParent() { abstract val id: String } and a…
jpganz18
  • 5,508
  • 17
  • 66
  • 115
3
votes
1 answer

IgnoreUnknownKeys for one type only with Kotlinx and Ktor

I am using Kotlinx serialization in a Ktor-app, and looking for an equivalent of Jacksons @JsonIgnoreProperties(ignoreUnknown = true) annotation. I am aware of the install(ContentNegotiation) { json(Json{ ignoreUnknownKeys = true }) } I have…
user1119371
  • 417
  • 2
  • 7
  • 13
3
votes
1 answer

KotlinX Serialization of Built-in Classes

Kotlinx docs don't seem to cover this, I am wondering if there is a way to write a custom Serializer for an existing class. In my case, I need to serialize PointF and Color. For PointF, I have done this: object MyPointFAsStringSerializer :…
Amir J
  • 123
  • 8
3
votes
2 answers

Can I use kotlinx classes in Kotlin scripts?

Is it possible to import classes from kotlinx package in a simple Kotlin script? myscript.kts: import kotlinx.serialization.* import kotlinx.serialization.json.* println("") Running the above script with kotlinc -script myscript.kts gives this…
Mahozad
  • 18,032
  • 13
  • 118
  • 133
1
2 3