• c

    CLOVIS

    2 years ago
    Edited the message to feature the correct Kotlin version, but the problem is still there...
    c
    turansky
    3 replies
    Copy to Clipboard
  • m

    Michał Kalinowski

    2 years ago
    Hey, so maybe someone know why with this code:
    @Serializable
    data class SerializableTransformation(
      val translateX: Float = 0f,
      val translateY: Float = 0f,
      val rotateY: Float = 0f
    )
    kotlinx-serialization give me an exception:
    Exception in thread "main" kotlinx.serialization.MissingFieldException: Field 'rotateY' is required, but it was missing
    I thought that default values make fields optional for serialization, but maybe I'm wrong Thanks in advance :kotlin-flag:
    m
    Robert Jaros
    +2
    7 replies
    Copy to Clipboard
  • Ivann Ruiz

    Ivann Ruiz

    2 years ago
    Just a heads up, this weekend I tried starting a multiplatform project using kotlinx.serialization library and just couldn't figure out how to get it to serialize a response. I kept having the error I show below. I suspect it has something to do with the versions of the libraries I was using. I know that if you're using
    Kotlin plugin version 1.3.70
    you MUST use
    kotlinx.serialization version 0.20.0
    because it's NOT backwards compatible. Spent a whole day stuck, finally ended up reverting back to
    Kotlin plugin 1.3.61
    and
    kotlinx.serialization 0.14.0
    and it finally worked. Also used
    ktor 1.3.1
    . Just wondering if anybody has tried using the
    kotlinx.serialization
    library with
    Kotlin 1.3.70
    successfully? Here's a GitHub gist: https://gist.github.com/lamvann/d441b2529d4f3b164edc5947401a1e4f
    E/AndroidRuntime: FATAL EXCEPTION: main
        Process: org.jetbrains.kotlin.mpp_app_android, PID: 28267
        java.lang.NoSuchFieldError: No field Companion of type Lkotlinx/serialization/json/Json$Companion; in class Lkotlinx/serialization/json/Json; or its superclasses (declaration of 'kotlinx.serialization.json.Json' appears in /data/app/org.jetbrains.kotlin.mpp_app_android-InBSbzMi00a168C538jy0g==/base.apk)
            at io.ktor.client.features.json.serializer.KotlinxSerializer.<init>(KotlinxSerializer.kt:22)
    Ivann Ruiz
    russhwolf
    +2
    5 replies
    Copy to Clipboard
  • s

    Sebastien Leclerc Lavallee

    2 years ago
    Let say I have a class:
    @Serializable
    data class SomeClass(val a: Int)
    And a function that can receive pretty much everythin:
    fun someFunction(object: Any)
    How can I check that the function’s parameter is Serializable? I did try something like:
    when (object) {
       is Serializable -> doSomething()
    }
    But that doesn’t work. Someone has some lights to help me?
    s
    c
    +1
    3 replies
    Copy to Clipboard
  • i

    ivan.savytskyi

    2 years ago
    hey folks, I ran into issue after migrating to 0.20.0:
    java.lang.NoSuchMethodError: No direct method <init>(Ljava/lang/String;Lkotlinx/serialization/internal/GeneratedSerializer;I)V in class Lkotlinx/serialization/internal/SerialClassDescImpl; or its super classes (declaration of 'kotlinx.serialization.internal.SerialClassDescImpl' appears in ....)
    . Am I missing any migration steps? Found similar issue: https://github.com/Kotlin/kotlinx.serialization/issues/736 that still reproduces for me
    i
    turansky
    +1
    7 replies
    Copy to Clipboard
  • tylerwilson

    tylerwilson

    2 years ago
    Moving here, since it appears to be related to the serialization plugin, though only for native - JVM is working fine.
    tylerwilson
    Erik Christensen
    18 replies
    Copy to Clipboard
  • Shan

    Shan

    2 years ago
    Hey all. I have an endpoint that's unstable (data models are changing semi-frequently without a versioning system- it's an ongoing discussion) for an application I am working on. I am using a
    Json(context = serializationContext)
    where my
    serializationContext
    is a
    SerializersModule
    which contains all of my contextual serializer mappings, to stringify/parse values, but need it to able to adapt to situations where the data model has changed server-side for older app versions that don't have an updated model. I could use
    Json.nonstrict
    for parsing/writing, but is there any way to use it with my
    serializationContext
    and have it fall back to
    nonstrict
    if the models don't match? Or is there a better way to do this that I'm missing?
    Shan
    m
    3 replies
    Copy to Clipboard
  • altavir

    altavir

    2 years ago
    Hi, I am still struggling with tree-like serializers. I have following serializeable node:
    data class NodeItem<M : Meta>(val node: M) : MetaItem<M>() {
            override fun toString(): String = node.toString()
    
            @Serializer(NodeItem::class)
            companion object : KSerializer<NodeItem<out Meta>> {
                ...
            }
        }
    M
    is the recursive generics type. It is actually ignored in the serializer since we always use top type. When I use it, I get
    class hep.dataforge.meta.MetaBuilder is not registered for polymorphic serialization in the scope of class hep.dataforge.meta.Meta
    . Is it possible to somehow bypass polymorphic serializers and actually use interface type for serialization?
    altavir
    1 replies
    Copy to Clipboard
  • Paulius Ruminas

    Paulius Ruminas

    2 years ago
    Hi, we were using
    kotlinx.serialization.internal.CommonEnumSerializer
    to serialize an enum:
    object DayTypeSerializer : CommonEnumSerializer<DayType>(
        "DayType",
        DayType.values(),
        DayType.values().map { it.type.toString() }.toTypedArray()
    )
    
    @Serializable(with = DayTypeSerializer::class)
    enum class Day(val type: Int) {
        MONDAY(1),
        TUESDAY(2),
        WEDNESDAY(3),
        THURSDAY(4),
        FRIDAY(5),
        SATURDAY(6),
        SUNDAY(7),
        HOLIDAY(8),
    }
    After 0.20.0 update
    CommonEnumSerializer
    is removed. Is there another way to achieve this?
    Paulius Ruminas
    s
    +2
    6 replies
    Copy to Clipboard
  • n

    napperley

    2 years ago
    Wondering how to handle a situation where a untyped JSON array (always containing two items; first item Double, second item String) is returned as part of a HTTP response body.
    n
    Dominaezzz
    8 replies
    Copy to Clipboard