https://kotlinlang.org logo
Title
m

Michal Janos

03/15/2023, 11:18 PM
Hi, I work on migration to IR compiler, but I have issue with serializer for example this code work with JVM and Legacy JS, but not with IR JS
@Test
fun serializeTest() {
    @Serializable
    data class Data(val a: Int, val b: String)

    val obj: Data = Json.decodeFromString("""{"a":42, "b": "str"}""")
    assertEquals(42, obj.a)
}
error:
SerializationException: Serializer for class 'Data' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.

On Kotlin/JS explicitly declared serializer should be used for interfaces and enums without @Serializable annotation
SerializationException: Serializer for class 'Data' is not found.
Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied.
it can be fixed with
Json.decodeFromString(Data.serializer(), """{"a":42, "b": "str"}""")
but in our code we have used serializer for parse json to list Kotlin 1.8.10
kotlin("plugin.serialization") version "1.8.10"
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
a

Adam S

03/16/2023, 11:04 AM
do you have React wrappers? If so, maybe it’s the same issue as this one https://github.com/Kotlin/kotlinx.serialization/issues/2202
m

Michal Janos

03/16/2023, 11:14 AM
thanks for response, but there is no kotlin-wrappers
So, I have update I try this test on new MPP project with IR and it works correctly. After lot of investigation and trying issue was with old version
gradle-plugin
and maybe
kotlin.js.compiler=ir
helps too. So problem with serializer looks like fixed, but actualy I need to investigate some failed tests (16 of 23 284)