• d

    DJ

    3 months ago
    I have a json file I am parsing with ktx.serialization which has a
    $schema
    key at the top level. I am parsing it into a
    Map<String, Def>
    (Def is a class I have defined), so when the string value in the
    $schema
    key is encountered, it throws an exception. I simply want to ignore the value of the
    $scheam
    key, what is the best way to do this?
    d
    k
    2 replies
    Copy to Clipboard
  • k

    kotlinforandroid

    3 months ago
    I need some help with deserialization. I get an
    IndexOutOfBoundsException
    and I do not really get why. (thread)
    k
    1 replies
    Copy to Clipboard
  • a

    Adam S

    3 months ago
    I can define a serializer for a class in many places. On the class with
    @Serializable
    , on the field, for a whole file, in multiple ways with a SerializersModules, and there's also reflection. Is the order of priority defined somewhere? I'm asking because I want to see how to override a serializer that's defined on a class with
    @Serializable(with = ...)
    , and it's not clear in which order serializers are considered and selected.
    a
    e
    3 replies
    Copy to Clipboard
  • k

    Katyrin Roman

    3 months ago
    After updating from com.android.tools.build:7.0.4 to com.android.tools.build:7.2.1, the application began to crash when calling the <reified T> StringFormat.encodeToString(value: T): String method. The bug manifests itself only in the release version, where there is: minifyEnabled true, shrinkResources true Has anyone come across a similar situation and have a solution?
    k
    1 replies
    Copy to Clipboard
  • ankushg

    ankushg

    3 months ago
    Hey all! At some point, we started running into this issue: https://github.com/Kotlin/kotlinx.serialization/issues/1940 It’s not impacting our
    main
    branch, but we have a branch where we’ve made a couple structural changes (with absolutely no new
    @Serializable
    classes) and things are just breaking for mysterious reasons 😞 Has anyone else here experienced it? Any ways to narrow down the cause?
    ankushg
    Simon Bruins
    3 replies
    Copy to Clipboard
  • Daniele Andreoli

    Daniele Andreoli

    3 months ago
    good morning, I’m sorry if this is a recurring or a trivial question but it’s my first time I had to write custom serializer/deserializer for a project and i’m a little confused. I have to migrate an old GSON Deserializer for a data class that look like this:
    @Serializable(with = PaymentInfoSerializer::class)
    data class PaymentInfo(
    val id: PaymentId,
    val amount: Float,
    val paidAt: String?,
    val productId: ProductId
    )
    The last field is a typealias for a Int type but it’s actually an evaluated one. The field is a field taken from an inner Json Object like this:
    "product":{"id":74}
    so the value is just the id field. The entire json is like this one:
    "id":22,"paidAt":null,"amount":720.0,"description":null,"product":{"id":74}
    So my problem is that I can’t use simple deserilization with dataclass because I have to keep the code working but i can’t figure out how a map object is actually descripted inside a desirializer. I’have written a descriptor like this but i’m not sure how ti could work as I have no way to tell it to take just the id field inside the map:
    override val descriptor: SerialDescriptor =
    buildClassSerialDescriptor("PaymentInfo") {
    element<PaymentId>("id")
    element<Float>("amount")
    element<String?>("paidAt", isOptional = true)
    element<Map<String, Int>>("product")
    }
    At the end, i’ve to find a way to tell serilization to do something like this in GSON:
    productId = jsonObject.get("product").asJsonObject.get("id").asInt
    I've read the doc but I can't find some example that actually seems to fit and since I have to migrate a lot of this custom serializer I'm tring to start with the correct structure. Is there someone who could help? Thanks
    Daniele Andreoli
    r
    5 replies
    Copy to Clipboard
  • Landry Norris

    Landry Norris

    3 months ago
    [Resolved] I’ve started seeing this error on iOS recently
    * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)
    `frame #0: 0x000000010d014d10 MyFramework`kfun:kotlinx.serialization.json.Json#encodeToString(kotlinx.serialization.SerializationStrategy<0:0&gt;;0:0){0§<kotlin.Any?>}kotlin.String [inlined] Composer at Composers.kt:13:9` I’m using a standard
    json.encodeToString(Model.serializer(), model)
    using
    private val json = Json {
        isLenient = true
        ignoreUnknownKeys = true
    }
    Everything works fine on Android, but fails on iOS. What should I be looking for?
    Landry Norris
    1 replies
    Copy to Clipboard
  • Chris Fillmore

    Chris Fillmore

    3 months ago
    Hi folks, I’m trying to find my way around R8 / ProGuard config. I’m just using a dummy test project with
    minifyEnabled true
    on the release build. My question is, is it necessary to configure ProGuard for Kotlin serialization, if you always provide a serializer explicitly? So I mean, in every case I call it like this:
    serializer.decodeFromString(MyData.serializer(), json)
    // or
    serializer.encodeToString(MyData.serializer(), myObj)
    On observation, my program seems to work fine with obfuscation enabled, without any ProGuard configuration, if I am passing the serializer like this. This seems to contradict the docs:
    The library works on Android, but, if you’re using ProGuard, you need to add rules to your
    <http://proguard-rules.pro|proguard-rules.pro>
    configuration to cover all classes that are serialized at runtime.
    Chris Fillmore
    e
    3 replies
    Copy to Clipboard
  • Andrey Tabakov

    Andrey Tabakov

    3 months ago
    Why variable that starts with
    is
    is omitted while serialization? I have data class
    @Serializable
    public data class Config(
        val isVariable: String,
        val anotherVariable: String
    )
    
    Config("omit", "value")
    Output will be:
    {anotherVariable:"value"}
    P.S. isVariable should be boolean, I know, anyway it should be a String in my case
    Andrey Tabakov
    e
    3 replies
    Copy to Clipboard
  • ermac10k

    ermac10k

    3 months ago
    Hello! Are there any plans to fix this: https://github.com/Kotlin/kotlinx.serialization/issues/1051 It’s a real pain in the neck. Unfortunately, it is the reason to reject using kotlin.serialization in systems with money involved
    ermac10k
    2 replies
    Copy to Clipboard