https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
serialization
  • d

    diesieben07

    10/13/2020, 4:09 PM
    I'm experimenting with writing my own serialization format. How would I best handle it, if the underlying format can handle certain types (like for example a Timestamp) natively? Would I detect this type in
    Encoder#encodeSerializableValue
    and act accordingly?
    r
    s
    • 3
    • 3
  • s

    Stylianos Gakis

    10/13/2020, 9:34 PM
    I decided to try out Kotlin Serialization in a Jetpack Compose project and I am experiencing some issues. Basically the moment I include the "@Serializable" annotation over a data class, the compilation never goes over the app:compileDebugKotlin step, it's stuck there infinitely. If I just remove that one line it compiles just fine. Is there a template somewhere that I can follow to file this as a potential bug?
    e
    • 2
    • 3
  • a

    aleksey.tomin

    10/14/2020, 1:12 PM
    I try to use kotlin.serialization (1.0.0) with ktor (1.4.1) and kotlin (1.4.10) I have too classes:
    @Serializable
    class Holder<T> (val value: T)
    
    @Serializable
    class StringHolderDirect (val value: String)
    The both work with Json directly
    Json.encodeToString(StringHolderDirect(""))
        Json.encodeToString(Holder(""))}
    but with ktor works only the second, the first produces an error:
    val client = HttpClient(CIO) {
            this.install(JsonFeature) { serializer = KotlinxSerializer() }
        }
        <http://client.post|client.post><String>(URL) {
            contentType(ContentType.Application.Json)
            body = Holder("")
        }
    On run:
    Exception in thread "main" kotlinx.serialization.SerializationException: Serializer for class 'Holder' is not found.
    Mark the class as @Serializable or provide the serializer explicitly.
            at kotlinx.serialization.internal.Platform_commonKt.serializerNotRegistered(Platform.common.kt:91)
            at kotlinx.serialization.SerializersKt__SerializersKt.serializer(Serializers.kt:130)
            at kotlinx.serialization.SerializersKt.serializer(Unknown Source)
            at io.ktor.client.features.json.serializer.KotlinxSerializerKt.buildSerializer(KotlinxSerializer.kt:77)
    What do I wrong?
    j
    r
    s
    • 4
    • 8
  • a

    aarjav

    10/14/2020, 2:00 PM
    Given a class
    data class Node<T: Any>(val id: String, val type: String, val value: T)
    , is it possible to deserialize
    value
    based on the
    type
    field?
    g
    s
    • 3
    • 8
  • t

    Tomas Kormanak

    10/14/2020, 2:16 PM
    Is there a way how to deserialize JSON into dynamic object? For example I have a data class, but I don't know the structure of prop2
    @Serializable
    data class (
    val prop1:String
    val prop2:dynamic
    )
    and JSON:
    {
      "prop1": "somestring",
      "prop2": {
        "a": 1,
        "b": 2
      }
    }
    g
    a
    • 3
    • 3
  • o

    Olaf Gottschalk

    10/14/2020, 2:57 PM
    I wanted to switch from Jackson to kotlinx serialization. But in my project I use two aspects heavily:
    @JsonRawValue
    for a string that already IS a valid Json string that needs to be put into the encoded result without any intervention, no escaping, nothing - and secondly I always work on unknown structures using
    Map<String, Any?>
    as my data values. How can kotlinx-serialization do these two things?
    👍 1
    t
    a
    • 3
    • 3
  • b

    Big Chungus

    10/15/2020, 2:57 PM
    Hi guys, is it possible to deserialize json into unknown class (class provided by library consumer) like in gson for example via
    Gson().fromJson(<str>, <any java class>.class)
    v
    s
    e
    • 4
    • 30
  • j

    jaqxues

    10/15/2020, 6:38 PM
    Hello, I previously used Gson and used the "Type" parameter pretty often, to serialize more complex elements. When i now wanted to switch to kotlinx.serialization, this was the thing that ended up not working for me.
    @OptIn(InternalSerializationApi::class)
    fun main() {
        val pairJson = """
            { 
              "first": "a",
              "second": 0
            }
        """.trimIndent()
        println(Json.decodeFromString(serializer<Pair<String, Int>>(), pairJson))
    
        println(Json.decodeFromString(serializer(object : TypeToken<Pair<String, Int>>() {}.type), pairJson))
    }
    As you can see, when using reified types, it works just fine, but as soon as i try to use type:
    kotlinx.serialization.SerializationException: Serializer for class 'Pair' is not found.
    Now, I know that TypeToken is a class and weird type generic stuff from Gson, so I am not necessarily asking for a fix. I just do not know what would be the best way to handle this problem. I suppose implementing the full kotlin reflection library and using
    createType
    to create generic KTypes? The type has to be stored in a property, so imagine a
    Data
    container that needs the type
    class Data {
        // Allow KClass for simpler JsonElements to be deserialized
        val type: Either<KClass<*>, KType<*>>
    
        fun deserialize() { ... }
    }
    r
    s
    • 3
    • 9
  • m

    manlan

    10/16/2020, 9:34 AM
    kotlinx.serialization.SerializationException: Serializer for class 'UUID' is not found.
    Mark the class as @Serializable or provide the serializer explicitly.
    I know UUID is not serializable. How do I do provide a serializer in Ktor?
    a
    s
    • 3
    • 5
  • k

    KamilH

    10/16/2020, 9:55 AM
    Does anyone else faces following problem
    e: Compilation failed: Deserializer for declaration public kotlinx.serialization/UpdateMode|null[0] is not found
    when running
    compileKotlinIos
    task? I’m using
    kotlinx-serialization-core:1.0.0
    on
    1.0.0-RC2
    it was working properly
    v
    • 2
    • 4
  • k

    KamilH

    10/16/2020, 10:06 AM
    Another issue: I’m working on a multiplatform library and I’m using both
    ktor 1.4.1
    and
    serialization 1.0.0
    . When I’m building and publishing it is works fine, but when I’m trying to use it in another project I’m getting a lot of “duplication” errors:
    Duplicate class kotlinx.serialization.BinaryFormat found in modules jetified-kotlinx-serialization-core-jvm-1.0.0.jar (org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.0.0) and jetified-kotlinx-serialization-runtime-0.20.0.jar (org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0)
    I found some message that suggest to exclude it in a following way:
    implementation(io.ktor:ktor-client-serialization:1.4.1) {
        exclude(group = "org.jetbrains.kotlinx", module = "kotlinx-serialization-runtime")
    }
    but it doesn’t help
    s
    a
    • 3
    • 6
  • b

    Big Chungus

    10/17/2020, 12:34 AM
    Has anyone writen a serial format lib for XML yet?
    t
    • 2
    • 1
  • k

    kartik1712

    10/18/2020, 7:34 AM
    e: java.lang.IllegalStateException: Cannot get FQ name of local class: class <no name provided> : at.yawk.javap.model.ConfigProperty.Choice<kotlin.String?> defined in private final val propertyLanguageVersion: <no name provided> defined in at.yawk.javap.model.ConfigProperties
    	at org.jetbrains.kotlin.serialization.DescriptorAwareStringTable$DefaultImpls.getFqNameIndex(DescriptorAwareStringTable.kt:26)
    	at org.jetbrains.kotlin.serialization.StringTableImpl.getFqNameIndex(StringTableImpl.kt:25)
    	at org.jetbrains.kotlin.serialization.DescriptorSerializer.getClassifierId(DescriptorSerializer.kt:729)
    	at org.jetbrains.kotlin.serialization.DescriptorSerializer.fillFromPossiblyInnerType(DescriptorSerializer.kt:601)
    	at org.jetbrains.kotlin.serialization.DescriptorSerializer.type$serialization(DescriptorSerializer.kt:568)
    	at org.jetbrains.kotlin.serialization.DescriptorSerializer.typeId(DescriptorSerializer.kt:535)
    	at org.jetbrains.kotlin.serialization.DescriptorSerializer.propertyProto(DescriptorSerializer.kt:252)
    	at org.jetbrains.kotlin.serialization.DescriptorSerializer.classProto(DescriptorSerializer.kt:113)
    	at org.jetbrains.kotlin.cli.metadata.MetadataSerializer$PackageSerializer.serializeClasses(MetadataSerializer.kt:149)
    	at org.jetbrains.kotlin.cli.metadata.MetadataSerializer$PackageSerializer.run(MetadataSerializer.kt:133)
    	at org.jetbrains.kotlin.cli.metadata.MetadataSerializer$performSerialization$1.visitClassOrObject(MetadataSerializer.kt:86)
    	at org.jetbrains.kotlin.psi.KtVisitorVoid.visitClassOrObject(KtVisitorVoid.java:465)
    	at org.jetbrains.kotlin.psi.KtVisitorVoid.visitClassOrObject(KtVisitorVoid.java:21)
    	at org.jetbrains.kotlin.psi.KtVisitor.visitObjectDeclaration(KtVisitor.java:37)
    	at org.jetbrains.kotlin.psi.KtVisitorVoid.visitObjectDeclaration(KtVisitorVoid.java:413)
    	at org.jetbrains.kotlin.psi.KtVisitorVoid.visitObjectDeclaration(KtVisitorVoid.java:1013)
    	at org.jetbrains.kotlin.psi.KtVisitorVoid.visitObjectDeclaration(KtVisitorVoid.java:21)
    	at org.jetbrains.kotlin.psi.KtObjectDeclaration.accept(KtObjectDeclaration.kt:63)
    	at org.jetbrains.kotlin.psi.KtElementImplStub.accept(KtElementImplStub.java:59)
    	at org.jetbrains.kotlin.cli.metadata.MetadataSerializer.performSerialization(MetadataSerializer.kt:60)
    	at org.jetbrains.kotlin.cli.metadata.MetadataSerializer.serialize(MetadataSerializer.kt:48)
    	at org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler.doExecute(K2MetadataCompiler.kt:111)
    	at org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler.doExecute(K2MetadataCompiler.kt:40)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:86)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
    	at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1549)
    	at jdk.internal.reflect.GeneratedMethodAccessor164.invoke(Unknown Source)
    	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    	at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
    	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
    	at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
    	at java.base/java.security.AccessController.doPrivileged(AccessController.java:691)
    	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:587)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:828)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:705)
    	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:704)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
    	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
    	at java.base/java.lang.Thread.run(Thread.java:832)
    s
    • 2
    • 1
  • m

    Matthew Bartos

    10/20/2020, 7:50 AM
    Hey, hey! 👋 I’m trying to convince my team to switch to the
    kotlinx.serialization
    and I want to show them the performance comparison between
    GSON
    and
    kotlinx.serialization
    Can anyone show me some proper benchmarks?
    o
    a
    • 3
    • 5
  • a

    Alec Muffett

    10/20/2020, 3:48 PM
    Hi Everyone! I am a Kotlin noob (but have about 21 years of Java on-and-off, so I got that goin for me which is nice) — and I am playing with serialisation of immutable, signed objects to send over the network. I am starting to read up on Kotlin serialisation but - in parallel with that - I was wondering if anyone had enough experience of Square.com's "Wire" library (https://square.github.io/wire/ - see
    Wire Kotlin
    section) which I've used in Java before to provide elegant/ish cross-platform serialisation. What I am seeking is: perspective on whether the problems which Wire addresses for Java, are still an issue with native Kotlin protobuf support and/or serialisation? Typically Java coders who like Wire are looking for generation of lightweight (field-not-getter) code for Java - to reduce method proliferation - and simpler syntax. Wire has Kotlin support, but given Kotlin's pragmatism, I am wondering how necessary it is, please?
    g
    • 2
    • 4
  • j

    Javier

    10/21/2020, 10:05 AM
    Should avoid
    @Serializer
    in companion objects?
    d
    b
    • 3
    • 6
  • c

    christophsturm

    10/21/2020, 11:08 AM
    when i upgrade my project from 1.4.0 to 1.4.10 i get this error with the IR backend:
    Unbound public symbol for public kotlinx.serialization.json/JsonElementSerializer.patch
    • 1
    • 2
  • a

    andyg

    10/22/2020, 9:19 AM
    is it possible to write a custom serializer (kotlinx.serialization) for serializing only, and not overriding deserialize? I get an error if I don't specifically override deserialize too. Alternatively, how can I write the deserialize method to use the default or built-in deserializer? (this is for a data class, not a primitive). There's no
    super
    to leverage. Thank you.
    m
    r
    • 3
    • 3
  • s

    savrov

    10/23/2020, 4:38 PM
    Hi, I have followed a tutorial to create a custom serialization for my generic class. But i am still stacked with error:
    SerializationException: Serializer for class 'ApiResponse' is not found. Mark the class as @Serializable or provide the serializer explicitly.
    My
    ApiResponse
    class looks like this:
    @Serializable(with = ApiResponseSerializer::class)
    class ApiResponse<T>(
        @SerialName("data")
        val data: T? = null,
        @SerialName("error")
        val error: ApiError? = null
    )
    And
    ApiResponseSerializer
    , that is used in annotation above is:
    class ApiResponseSerializer<T>(private val dataSerializer: KSerializer<T>) : KSerializer<ApiResponse<T>> {
        
        override val descriptor: SerialDescriptor = buildClassSerialDescriptor("ApiResponseDataSerializer") {
            val dataDescriptor = dataSerializer.descriptor
            element("data", dataDescriptor)
            element("error", ApiError.serializer().descriptor)
        }
        
        override fun deserialize(decoder: Decoder): ApiResponse<T> =
            decoder.decodeStructure(descriptor) {
                var data: T? = null
                var error: ApiError? = null
                loop@ while (true) {
                    when (val i = decodeElementIndex(descriptor)) {
                        0 -> data = decodeSerializableElement(descriptor, i, dataSerializer)
                        1 -> error = decodeSerializableElement(descriptor, i, ApiError.serializer())
                        CompositeDecoder.DECODE_DONE -> break
                        else -> throw SerializationException("Unknown index $i")
                    }
                }
                ApiResponse(data, error)
            }
            
        override fun serialize(encoder: Encoder, value: ApiResponse<T>) {
            encoder.encodeStructure(descriptor) {
                encodeNullableSerializableElement(descriptor, 0, dataSerializer, value.data)
                encodeNullableSerializableElement(descriptor, 1, ApiError.serializer(), value.error)
            }
        }
    }
    Then, when i’m trying to serialise my data object, i receive an exception I’ve mentioned above.
    Json.encodeToString(ApiResponse(data = response.data))
    ---- OR ----
    Json.encodeToString(ApiResponse.serializer(T::class.serializer()), ApiResponse(data = response.data))
    Can someone tell me where i’m wrong? Thank you.
    a
    • 2
    • 2
  • j

    jaqxues

    10/24/2020, 3:39 PM
    The gradle plugin is freezing
    app:compileDebugKotlin
    for me now, is that a known issue or what is going on?
    g
    b
    • 3
    • 21
  • p

    Paul Griffith

    10/26/2020, 11:43 PM
    Is there a way to require the type-discriminator's presence during serialization, even if the serialization case doesn't actually need discriminating? That is, I'm putting a specific member of a sealed class inside a sealed class, and, for the API's sake, I want to include the
    type
    key, but if I type the field in the data class to the specific sealed class member, it just serializes the different properties and does not include the type discriminator (by design, surely - but I'm hoping to avoid it anyways)
    • 1
    • 2
  • t

    Tatum Alenko

    10/27/2020, 7:07 AM
    This might sound like a silly question but does anyone mind explaining what characterizes kotlinx.serialization to be considered "reflectionless"?
    s
    t
    • 3
    • 3
  • e

    Evilthreads669966

    10/27/2020, 8:59 AM
    I'm trying to serialize lambdas into a Room database table. I've been working on it for a week and have switched from Gson to kotlinx serialization. Has anyone ever come across this. I've tried doing SAM, FunctionalInteface from jdk, and an open class with an open function. Kotlin states that lambdas are serializable by default. I'm performing the serialization for the function types inside of a Converters class
    😔 1
    😮 1
    s
    • 2
    • 2
  • k

    kingsley

    10/27/2020, 10:33 AM
    🙏
    k
    j
    • 3
    • 19
  • n

    Nikky

    10/27/2020, 12:03 PM
    so.. serializable classes with fields default values having dependencies on other fields is not working well.. what workarounds would you recommend for that?
    e
    l
    • 3
    • 3
  • s

    starsep

    10/28/2020, 12:06 PM
    Is it possible to try deserializing String to one of types provided?
    FooResponse
    is sealed class, I don't control response and therefore cannot add type discriminator as described in https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/polymorphism.md#sealed-classes At the moment I use this ugly code, is there a better way?
    val jsonData = jsonSerializer.parseToJsonElement(responseData)
    
    try {
        Json.decodeFromJsonElement<FooResponse.SuccessData>(jsonData)
    } catch (e: SerializationException) {
        try {
            Json.decodeFromJsonElement<FooResponse.AnotherCase>(jsonData)
        } catch (e: SerializationException) {
            Json.decodeFromJsonElement<FooResponse.ErrorData>(jsonData)
        }
    }
    d
    s
    e
    • 4
    • 3
  • j

    Jovan

    10/28/2020, 12:42 PM
    Hi guys. I need some help.
    val module = SerializersModule {
        polymorphic(Project::class) {
            subclass(OwnedProject::class)
        }
    }
    So, I was looking into Open polymorphism and can’t get it working for me. For some reason it only works when I have two levels, like in the example from above. How to init SerializersModule in case I have 3+ levels (e.g. OwnedProject is parent of OwnedChildeProject)?
    s
    • 2
    • 2
  • r

    rnentjes

    10/28/2020, 3:17 PM
    Hi, documentation for serialization seems to be out of date, is that correct? For example: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/polymorphism.md This doesn't work anymore with 1.0.0:
    val module = SerializersModule {
        polymorphic(Project::class) {
            subclass(OwnedProject::class)
        }
    }
    Is there up to date documentation somewhere?
    s
    • 2
    • 2
  • j

    Joaquim Ley

    10/28/2020, 3:23 PM
    (I’ve initially posted this in #ktor but it feels like it might make more sense to ask here: ---- Hello fellow kotliners, I’m haivng an issue where my ktor client is not parsing the response correctly.. The body “ends” unexpectedly, looking at the logs is simply stops “parsing the json” from the response. I’ve double checked with postman and the response from the API is correct.
    [14:55] kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 82: Expected string literal with quotes.
    For some context the body seems to be cut randomly and the rest of the response is not parsed, using latest versions for both ktor and kotlinx.serialisation
    r
    • 2
    • 2
  • r

    rnentjes

    10/28/2020, 3:36 PM
    Anyone run into this one yet?:
    java.lang.NoSuchMethodError: kotlinx.serialization.internal.AbstractPolymorphicSerializer.findPolymorphicSerializerOrNull(Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)Lkotlinx/serialization/SerializationStrategy;
    	at kotlinx.serialization.PolymorphicSerializerKt.findPolymorphicSerializer(PolymorphicSerializer.kt:96)
    	at kotlinx.serialization.json.internal.PolymorphicKt.findActualSerializer(Polymorphic.kt:29)
    	at kotlinx.serialization.json.internal.PolymorphicKt.access$findActualSerializer(Polymorphic.kt:1)
    	at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:226)
    	at kotlinx.serialization.encoding.AbstractEncoder.encodeSerializableElement(AbstractEncoder.kt:81)
    	at kotlinx.serialization.internal.MapLikeSerializer.serialize(CollectionSerializers.kt:123)
    	at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:223)
    	at kotlinx.serialization.encoding.AbstractEncoder.encodeSerializableElement(AbstractEncoder.kt:81)
    This is KMM with serialization plugin 1.4.10 and dependency 'kotlinx-serialization-json:1.0.0' in common. The error happens on the jvm with a sealed class.
    s
    • 2
    • 2
Powered by Linen
Title
r

rnentjes

10/28/2020, 3:36 PM
Anyone run into this one yet?:
java.lang.NoSuchMethodError: kotlinx.serialization.internal.AbstractPolymorphicSerializer.findPolymorphicSerializerOrNull(Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)Lkotlinx/serialization/SerializationStrategy;
	at kotlinx.serialization.PolymorphicSerializerKt.findPolymorphicSerializer(PolymorphicSerializer.kt:96)
	at kotlinx.serialization.json.internal.PolymorphicKt.findActualSerializer(Polymorphic.kt:29)
	at kotlinx.serialization.json.internal.PolymorphicKt.access$findActualSerializer(Polymorphic.kt:1)
	at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:226)
	at kotlinx.serialization.encoding.AbstractEncoder.encodeSerializableElement(AbstractEncoder.kt:81)
	at kotlinx.serialization.internal.MapLikeSerializer.serialize(CollectionSerializers.kt:123)
	at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:223)
	at kotlinx.serialization.encoding.AbstractEncoder.encodeSerializableElement(AbstractEncoder.kt:81)
This is KMM with serialization plugin 1.4.10 and dependency 'kotlinx-serialization-json:1.0.0' in common. The error happens on the jvm with a sealed class.
s

sandwwraith

10/28/2020, 6:30 PM
maybe you have old version (1.0.0-RC or 0.20.0) included somewhere in the classpath
r

rnentjes

10/28/2020, 7:24 PM
Thx, you are right, there was another version included through a ktor dependency.
View count: 15