https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
j

Jan Stoltman

07/27/2019, 8:42 PM
I'm trying to parse a Json in a backthread on native using kotlinx.serializer, but it fails with InvalidMutability exception. it used to work just fine with kotlin 1.3.30 and serialization 10.0 but fails at 1.3.41/11.1. Do you guys know if anything important changed in serialization between these two versions?
s

Sergioedcigreja

07/27/2019, 9:57 PM
Are you sure that your expected json from the server matches your Serializable class? Had an issue were I was expecting the wrong class for the request that I was doing
j

Jan Stoltman

07/28/2019, 4:50 AM
Everything works when I'm on main thread. It looks like serialization might be mutating something frozen
o

olonho

07/28/2019, 12:01 PM
basic JSON parsing with
Copy code
fun fetchBackground(url: String) {
    val backgroundWorker = Worker.start()
    val future = backgroundWorker.execute(TransferMode.SAFE, { url }) {
       try {
            jsonParser.parseJson(" {\"userId\":1,\"id\":1,\"title\":\"delectus aut autem\",\"completed\":false} ")
        } catch (e: SerializationException) {
            JsonPrimitive("<error: ${e.message}>")
        }
    }
    println(future.result.jsonObject["id"])
    backgroundWorker.requestTermination().result
}
seems to work. But parsing to data class may have issues, planned to be fixed in next release.
j

Jan Stoltman

07/28/2019, 5:28 PM
Yeah, I’m talking about parsing data classes with @serializable annotation. Is there any info on when next release can be expected?
3 Views