https://kotlinlang.org logo
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
  • g

    Greg Steckman

    10/09/2021, 6:51 PM
    Has anyone tried using serialization with Graalvm compiled to a native image?
    b
    e
    • 3
    • 36
  • g

    Gilles Barbier

    10/10/2021, 10:28 PM
    I'm coding a sort or RPC system: when the user calls a method, a proxy catches the parameters, serialize them, send them elsewhere where those parameters should be deserialized to call an actual implementation of the initial method: the issue is that I do not see any way to get the serializers needed for deserializing the parameters correctly. For each parameter, I can transport the class name also, but it's not enough to get the needed serializer. Any hints?
    b
    r
    +2
    • 5
    • 9
  • a

    aidanvii

    10/12/2021, 1:41 PM
    Is it possible to specify a custom class discriminator for polymorphic deserialisation or does it always have to be
    type
    ?
    s
    p
    • 3
    • 6
  • a

    aidanvii

    10/13/2021, 7:43 AM
    Does polymorphic deserialisation work with sealed interfaces? Just wondering as it’s ever so slightly less verbose than sealed classes.
    s
    p
    • 3
    • 3
  • a

    aidanvii

    10/13/2021, 12:29 PM
    Do default polymorphic type handlers work also for cases where the class discriminator is just not present in the json?
    d
    e
    • 3
    • 4
  • j

    Joost Klitsie

    10/15/2021, 7:48 AM
    Hi all! I have sort of my own take on the Kotlin Result class and I wish to serialize it. However, I fail to achieve this... Does someone know how to serialize the code I will attach to the thread? 🙂 Also, if someone already made the kotlin result class serializable, I would be interested in how that works 🙂
    e
    c
    p
    • 4
    • 30
  • b

    Big Chungus

    10/15/2021, 9:44 AM
    Getting this weird error in gradle when trying to add kotlinx-serialization-json
    org.gradle.internal.resolve.ArtifactNotFoundException: Could not find kotlinx-serialization-json-1.3.0-samplessources.jar (org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.0).
    Any tips?
    a
    • 2
    • 1
  • s

    snowe

    10/15/2021, 4:24 PM
    not sure how to even search this, how would I specify polymorphic serialization for a class where the type is at the top level, and that adjusts nested classes (tagged unions) within the top level class?
    response:
      productType: one | two
      nestedClassOne:
        anotherType: A | B
        nestedClassTwo:
          type that only shows up if productType is One
          or
          type that only shows up if productType is Two
        nestedClassThree:
          type that only shows up if anotherType is A
          type that only shows up if anotherType is B
    e
    p
    • 3
    • 10
  • u

    ursus

    10/16/2021, 11:44 AM
    Could one say serializing to protobuf is essentially the same as android's parcelable? Even in perf terms?
    j
    • 2
    • 2
  • a

    aidanvii

    10/18/2021, 2:36 PM
    Is deserialisation to enums case sensitive?
    s
    p
    • 3
    • 2
  • v

    Victor Ermolaev

    10/19/2021, 2:12 PM
    Hi there, I am developing a compiler plugin and, to test it, it has to be invoked together with the serialization plugin. I have currently this
    val compilation = KotlinCompilation()
      .apply {
        sources = listOf(source)
        compilerPlugins = listOf(MyPlugin())
    
        inheritClassPath = true
        messageOutputStream = System.out
      }
      .compile()
    I use kotlin-compile-testing, what do I need to add to the list of the compiler plugins to also invoke the serialization plugin?
    j
    • 2
    • 2
  • m

    Mihai Voicescu

    10/21/2021, 1:12 PM
    Is there any way I can specify a want a Serializer to be generated for a 3rd party dep? For example for https://github.com/michaelbull/kotlin-result
    j
    r
    a
    • 4
    • 4
  • j

    jw

    10/22/2021, 2:44 PM
    I'm trying to serialize a
    Box<T>
    where
    T
    is not actually used for serialization purposes and thus does not require a serializer. On JVM and JS this seems to just work, despite
    ContextualProvider.Argless
    receiving a list of serializers for type parameters on its
    invoke
    function. On native, however, this fails with an error about not finding a serializer for
    T
    with
    On Kotlin/Native explicitly declared serializer should be used for interfaces and enums without @Serializable annotation
    I do not control these types and as I said they are not serializable by nature. Is there something I can do to work around this? I started registering serializers that simply throw for the known types that are used inside the library, but that's not really viable as the library user can specify any type as the generic and will receive the same failure.
    • 1
    • 1
  • c

    Chris Fillmore

    10/25/2021, 2:21 PM
    I’m trying to enable minification on Android but I’m still getting
    Serializer for class 'b' is not found
    at runtime. I’ve added the ProGuard rules from here, substituting my app package name: https://github.com/Kotlin/kotlinx.serialization#android Is there any other step? Or something I’m missing?
    e
    r
    • 3
    • 12
  • m

    Michal Janos

    10/25/2021, 10:27 PM
    Hi, please, is there any way how to use
    encodeToString
    of double in json for js (multiplatform) with trailing zeros? In our case, we have test json with double format (with trailing zeros), we use
    decodeFromString
    and than
    encodeToString
    and compare it. For JVM it is allright, but in JS output is without trailing zeros.
    r
    e
    j
    • 4
    • 5
  • a

    aidanvii

    10/28/2021, 7:38 AM
    It seems
    JsonClassDiscriminator
    doesn’t work on interfaces. The only way I can get polymorphic serialisation/deserialisation to work with interfaces is to register a polymorphic serialiser for it manually (as the docs specify). This ignores
    JsonClassDiscriminator
    though, it only seems to work when the discriminator is the default key:
    type
    e
    • 2
    • 7
  • a

    aidanvii

    10/28/2021, 7:40 AM
    The last I checked,
    JsonClassDiscriminator
    isn’t even mentioned in the docs though 😕
    e
    • 2
    • 2
  • o

    Ovsyannikov Alexey

    10/30/2021, 2:35 PM
    Hello everybody 🙂 I am getting
    e: java.util.NoSuchElementException: Collection contains no element matching the predicate.
    with the stacktrace in reply to this message. The problem is that I can't find the source file which lead to this issue. Is there any way to get filename which was the source of issue?
    😒olved: 1
    • 1
    • 2
  • y

    Yoavya

    10/31/2021, 4:38 PM
    Hello, I am trying to create a gradle plugin that will generate files (serialized from data classes) from a gradle task that can run in another project. lets say that the classes that i am serializing are marked with some annotation 
    @Annot
     and i find all the relevant classes with reflection in the gradle task (I made sure to depend on kotlin compile so that the binaries are created). The problem is that when I try to use
    val clazz: Class<*>
    clazz.kotlin.serializer()
    I get a
    Serializer for class 'Type' is not found.
    (Type is the actual class that I found and is annotated with
    @Serializable
    and
    @Annot
    . What am I missing? why can’t I access the class serializer with the gradle task?
    • 1
    • 1
  • s

    Sam

    11/01/2021, 4:29 AM
    Hello everyone , I have a problem about
    JsonNames
    How can I resolve it?
    const val kotlinx_serialization_json = "1.3.0"
    const val gradle = "7.0.3"
    const val kotlin = "1.5.31"
    import kotlinx.serialization.ExperimentalSerializationApi
    import kotlinx.serialization.SerialName
    import kotlinx.serialization.Serializable
    import kotlinx.serialization.json.JsonNames
    
    
    @ExperimentalSerializationApi
    @Serializable
    data class CommonResponse constructor(
        @JsonNames("message", "results")
        val message: String = "",
        @SerialName("error")
        val error: String = ""
    )
    The root cause java.lang.IllegalArgumentException was thrown at: org.jetbrains.kotlinx.serialization.compiler.backend.jvm.SerializerCodegenImpl.addSyntheticAnnotationsToDescriptor(SerializerCodegenImpl.kt:123)
    	at org.jetbrains.kotlin.backend.common.CodegenUtil.reportBackendException(CodegenUtil.kt:239)
    	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:78)
    	at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generatePackage(CodegenFactory.kt:77)
    	at org.jetbrains.kotlin.codegen.DefaultCodegenFactory.generateModule(CodegenFactory.kt:62)
    	at org.jetbrains.kotlin.codegen.KotlinCodegenFacade.compileCorrectFiles(KotlinCodegenFacade.java:35)
    	at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.contextForStubGeneration(Kapt3Extension.kt:278)
    	at org.jetbrains.kotlin.kapt3.AbstractKapt3Extension.analysisCompleted(Kapt3Extension.kt:171)
    	at org.jetbrains.kotlin.kapt3.ClasspathBasedKapt3Extension.analysisCompleted(Kapt3Extension.kt:102)
    	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$invokeExtensionsOnAnalysisComplete(TopDownAnalyzerFacadeForJVM.kt:112)
    	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:122)
    	at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:86)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:252)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:243)
    	at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:113)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:243)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:90)
    	at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli$default(KotlinToJVMBytecodeCompiler.kt:56)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:169)
    	at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:52)
    	at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:92)
    	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.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:412)
    	at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:112)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:358)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally$default(IncrementalCompilerRunner.kt:300)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:160)
    	at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:81)
    	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:607)
    	at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:96)
    	at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1658)
    	at jdk.internal.reflect.GeneratedMethodAccessor109.invoke(Unknown Source)
    	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    	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(Native Method)
    	at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
    	at java.base/java.security.AccessController.doPrivileged(Native Method)
    	at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
    	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    	at java.base/java.lang.Thread.run(Thread.java:834)
    Caused by: java.lang.IllegalArgumentException: Can't use arguments with defaults for serializable annotations yet
    	at org.jetbrains.kotlinx.serialization.compiler.backend.jvm.SerializerCodegenImpl.addSyntheticAnnotationsToDescriptor(SerializerCodegenImpl.kt:123)
    	at org.jetbrains.kotlinx.serialization.compiler.backend.jvm.SerializerCodegenImpl.addElementsContentToDescriptor(SerializerCodegenImpl.kt:116)
    	at org.jetbrains.kotlinx.serialization.compiler.backend.jvm.SerializerCodegenImpl.generateSerialDescriptor(SerializerCodegenImpl.kt:77)
    	at org.jetbrains.kotlinx.serialization.compiler.backend.jvm.SerializerCodegenImpl.generateSerialDesc(SerializerCodegenImpl.kt:145)
    	at org.jetbrains.kotlinx.serialization.compiler.backend.common.SerializerCodegen.generate(SerializerCodegen.kt:36)
    	at org.jetbrains.kotlinx.serialization.compiler.backend.jvm.SerializerCodegenImpl$Companion.generateSerializerExtensions(SerializerCodegenImpl.kt:46)
    	at org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationCodegenExtension.generateClassSyntheticParts(SerializationCodegenExtension.kt:30)
    	at org.jetbrains.kotlin.codegen.ImplementationBodyCodegen.generateSyntheticPartsAfterBody(ImplementationBodyCodegen.java:448)
    	at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:135)
    	at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:305)
    	at org.jetbrains.kotlin.codegen.MemberCodegen.genSyntheticClassOrObject(MemberCodegen.java:319)
    	at org.jetbrains.kotlin.codegen.ClassBodyCodegen.generateBody(ClassBodyCodegen.java:113)
    	at org.jetbrains.kotlin.codegen.MemberCodegen.generate(MemberCodegen.java:132)
    	at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:305)
    	at org.jetbrains.kotlin.codegen.MemberCodegen.genClassOrObject(MemberCodegen.java:289)
    	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateClassesAndObjectsInFile(PackageCodegenImpl.java:119)
    	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generateFile(PackageCodegenImpl.java:138)
    	at org.jetbrains.kotlin.codegen.PackageCodegenImpl.generate(PackageCodegenImpl.java:70)
    	... 45 more
    r
    • 2
    • 3
  • z

    Zhiqiang Bian

    11/01/2021, 6:16 PM
    Hi guys! I cannot find a JSON:API library for Kotlin multiplatform. But I found a post in this channel that can convert almost any JSON:API string into an object. But then I had an issue with the dynamic relationship types. In the format specification, the relationship can be either
    to-one
    or
    to-many
    https://jsonapi.org/format/#crud-updating-relationships. It means that the value of
    data
    can be either an object (to-one) or an array of objects (to-many). Is there a way to deserialise `data`into either line 92 or 93?
    e
    • 2
    • 1
  • r

    Richard Gomez

    11/03/2021, 11:10 AM
    Is anyone able to help this poor soul find an old Gradle plugin that used to be hosted on
    <https://kotlin.bintray.com/kotlinx/>
    ? https://old.reddit.com/r/Kotlin/comments/qlcgzo/looking_for_an_old_dependency/
    v
    • 2
    • 5
  • a

    Ali Albaali

    11/03/2021, 5:38 PM
    I have an API which returns different types of values for the same key depending on the data like so: It returns String when data is empty:
    {
      "replies": ""
    }
    And list when data is not empty:
    {
      "replies" : [..data..]
    }
    Is there a way to handle this?
    😱 3
    b
    e
    a
    • 4
    • 7
  • g

    Gus

    11/04/2021, 5:05 PM
    Hi. I'd like to use Java's standard serialisation (e.g.,
    ObjectOutputStream
    ) with Kotlin data classes, and I tried using this library as follows:
    @Serializable
    internal data class FileSessionPublicKeyData(
        val keyId: ByteArray,
        val keyDer: ByteArray,
        val creationTimeTimestamp: Long
    )
    But I get
    java.io.NotSerializableException: tech.relaycorp.awala.keystores.file.FileSessionPublicKeyData
    when I try to save a value to a file using
    ObjectOutputStream
    , which I guess that
    @Selializable
    doesn't actually implement Java's
    Serializable
    interface. Is there any way to do this? I don't want to use JSON, protobuff, etc.
    e
    p
    • 3
    • 5
  • z

    Zhiqiang Bian

    11/04/2021, 11:05 PM
    Hi, I have two separate questions on Polymorphic Serializer. •
    line 36
    : Is it possible to set
    JsonContentPolymorphicSerializer
    for an abstract class programatically in run time? Something looks like
    AbstractRelationship.serializer = if (flag == 1) polySerializer1 else polySerializer2
    • I am deserialising
    AbstractRelationship
    based on the JsonElement inside. Is it possible to make polymorphic based on the map key on
    line 32
    , maybe with Contextual Serializer or Map Serializer?
    e
    • 2
    • 4
  • t

    tim

    11/05/2021, 1:59 PM
    Hi is it possible to specify the serializer for a specific type for my entire app? I've got lots of @file annotations for my InstantAsMilliLong and would be great to remove them all if I can declare it once somehow?
    👀 1
    r
    e
    • 3
    • 5
  • p

    Peter

    11/08/2021, 10:16 PM
    hi - does anyone know how to encode constants to json? eg
    data class Test(val a: String) {
      val b: String = "alwaysthesame"
    }
    i’m looking for
    Test("x")
    to be
    {"a": "x", "b": "alwaysthesame"}
    p
    b
    • 3
    • 5
  • p

    Peter

    11/12/2021, 10:07 PM
    is there a way to pretty print a
    JsonObject
    ?
    b
    • 2
    • 2
  • r

    Ryan Rolnicki

    11/14/2021, 6:18 AM
    Is there a way to 'skip' failed values in decoding? So given
    someSerialFormat.decodeFromString<List<MyType>>(text)
    some of the values in 'text' are bad...so say I have
    class MyType(val price: Double)
    , and inside the serialized text a small number of entries have "price: Unknown", can I just skip those somehow and still get back a list of all the successes?
    r
    • 2
    • 1
  • b

    benkuly

    11/14/2021, 5:29 PM
    Is it possible to determine which
    KSerializer
    of a List of KSerializers can be used for an object? Maybe with the descriptor?
    d
    f
    • 3
    • 7
Powered by Linen
Title
b

benkuly

11/14/2021, 5:29 PM
Is it possible to determine which
KSerializer
of a List of KSerializers can be used for an object? Maybe with the descriptor?
d

Dominaezzz

11/14/2021, 7:07 PM
What do you mean? Like if deserialization will be possible?
f

Fudge

11/14/2021, 9:19 PM
Technically you could try to deserialize and catch the exceptions that might occur. Could you provide more info on your use case?
b

benkuly

11/15/2021, 6:20 AM
I have polymorphic serialization, which is customizable by users of my library. They can put a
String
,
KClass
-Type and a
KSerializer
into a set. On serialization my own
KSerializer
searches for a matching
KClass
in this set, uses the users
KSerializer
to serialize the content and puts a
type
field into the Json from the
String
in the set. This works very good, as long as the user does not use generics. With generics, the search of a matching
KClass
does not include the generic type (->type erasure). Therefore it would be cool to use something like the
descriptor
to find a serializer, which can be used to serialize a given (generic) object.
d

Dominaezzz

11/15/2021, 1:07 PM
That's tricky, how is the deserialiser supposed to know which generic type to use based on the JSON data?
What does this hierarchy look like? It's probably matrix isn't it 😄 .
b

benkuly

11/15/2021, 1:23 PM
Yeah, Matrix... I decided to not support generic types, because it seems to be to compicated to detect the right serializer^^
d

Dominaezzz

11/15/2021, 1:27 PM
Also, you should use a serialiser module instead of manually using a set. Works better with kotlinx.
👍 1
View count: 2