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
  • m

    marcinmoskala

    03/26/2018, 6:22 PM
    https://github.com/Kotlin/kotlinx.serialization/issues/104
    t
    • 2
    • 2
  • c

    christophsturm

    03/28/2018, 10:56 AM
    if i wanted to use kotlin data classes in infinispan, which has its own externalizer interface (and uses jboss marshaller behind the scenes) , is kotlinx serialization the right api to start with?
    s
    • 2
    • 3
  • n

    neworldlt

    03/28/2018, 4:11 PM
    I noticed, there are sourcegen branch:
    <https://github.com/Kotlin/kotlinx.serialization/tree/sourcegen>
    . I am curious, is it because plugin isn’t a solution after all?
    s
    • 2
    • 4
  • e

    elizarov

    04/10/2018, 1:22 PM
    It still a POC in a separate branch and we don’t have a compiler plugin for K/N at the moment. It works with source-generating DSL (you describe your data classes in a DSL, then the source code of the data classes + serializers is generate). It is the fastest cross-platfrom solution we were able to prototype.
    👍 2
    a
    • 2
    • 1
  • h

    hastebrot

    04/13/2018, 9:56 AM
    I noticed a lot of work on moshi and kotlin code generation using kotlinpoet. https://github.com/square/moshi
    g
    • 2
    • 8
  • r

    rrva

    04/26/2018, 5:50 PM
    How can I use kotlinx-serialization to decode a protobuf message including wire format, using a framing which uses a prefix varint for the message length and then the message?
    g
    • 2
    • 1
  • n

    niklas

    04/27/2018, 8:04 AM
    I just found out about parsing
    dynamic
    objects https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/runtime_usage.md#dynamic-object-parser-js-only now I am wondering how I would serialize to a
    dynamic
    object. I guess I can do this:
    val jsonString = kotlinx.serialization.json.JSON.stringify(kotlinData)
    val dataAsPureJs = kotlin.js.JSON.parse(jsonString)
    s
    • 2
    • 3
  • b

    BorzdeG

    04/29/2018, 12:12 PM
    I’ll try to throw the question here ... https://github.com/Kotlin/kotlinx.serialization/issues/115
    s
    • 2
    • 2
  • c

    christophsturm

    05/24/2018, 12:09 PM
    does kotlinx-serialization work with idea 2018.2 and kotlin 1.2.50 eap?
    s
    • 2
    • 7
  • b

    bissell

    05/26/2018, 7:54 PM
    Does anyone know a way to parse a JSON field which could contain either a String or a Number to
    String
    or
    Long
    in Kotlin? My first thought was to attempt to read the field as a Number, and then if that fails (presumably because the field is another JSON type), then try to read it as String. But I haven't been able to write a method that can do this.
    g
    • 2
    • 6
  • b

    bissell

    05/28/2018, 12:40 AM
    ^ just checked Gson and it looks like they do this as well, at least with default settings. You can freely mix
    5
    and
    "5"
    and into fields of int/String type and the parser will not generate an error. I dunno, seems to me like "the wrong thing" to do
    s
    • 2
    • 4
  • c

    christophsturm

    06/01/2018, 5:08 PM
    why is the serilization support a separate plugin? wouldnt it be much easier if it was an unstable part of the normal plugin?
    g
    k
    • 3
    • 3
  • j

    jw

    06/04/2018, 9:33 PM
    where is "master" of the Gradle plugin? is it in the
    rr/kotlinx.serialization
    branch of the kotlin repo?
    s
    • 2
    • 1
  • h

    hastebrot

    06/07/2018, 2:57 PM
    so, will the JSON ast parser stuff enable us to use polymorphic json objects with
    @type
    entry? https://github.com/Kotlin/kotlinx.serialization/pull/132
    s
    b
    • 3
    • 4
  • s

    sandwwraith

    07/13/2018, 3:04 PM
    📣
    kotlinx.serialization
    version 0.6.0 just has been released. Short highlights: - Kotlin/Native limited support via JSON parser and JSON abstract syntax tree - Support of
    @SerialName
    and
    @SerialInfo
    annotations on classes - Auto-assigning protobuf ids using field index, if
    @SerialId
    is missing on property. Full changelog: https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md#v060--2018-07-13 _Note_:
    0.6.0
    is a release for stable
    1.2.5x
    compiler versions. If you’re using eap compiler, you should update to
    0.6.1-SNAPSHOT
    , which has the same feature set.
    🎉 18
    a
    • 2
    • 3
  • n

    neworldlt

    07/19/2018, 7:56 PM
    What I should do with polymorphic class in JS module? I have custom serializer. With
    0.5.0
    it worked well. With
    0.6.0
    compile is crashing with
    Can't locate polymorphic serializer definition
    s
    • 2
    • 8
  • e

    Edouard Goossens

    07/20/2018, 7:58 PM
    I’m building a JS module from Kotlin that uses serialization. This module is used by a “pure” JS (React Native) project (built with npm). It seems the kotlinx-serialization-runtime-js npm package has been deprecated. What is the recommended way of specifying the JS project’s dependency on the js serialization runtime library? Thanks!
    s
    • 2
    • 4
  • e

    Edouard Goossens

    07/29/2018, 12:04 PM
    I’m trying to use the JS DynamicObjectParser. I get a “Can’t locate default serializer for class” error. When I manually silence the error, deserialization works fine (the serializer exists and is found). It seems the runtime library doesn’t recognize the serializer as implementing KSerializer. It’s hard to try and reproduce this error in a minimal example because my project consists of several interacting modules. Maybe someone ran into this before? Happens with both kotlinx-serialization-runtime-js 0.5.1 and 0.6.0
    • 1
    • 1
  • k

    khairil.ushan

    08/01/2018, 12:01 PM
    I'm trying to use kotlinx.serialization in a MPP and run into this error. Is there something that I do wrong? 😞
    Exception in thread "ForkJoinPool.commonPool-worker-1" kotlinx.coroutines.experimental.CompletionHandlerException: Exception in completion handler InvokeOnCompletion[InvokeOnCompletion@55c536ef] for DeferredCoroutine{Completed}@48184828
    	at kotlinx.coroutines.experimental.JobSupport.notifyCompletion(JobSupport.kt:1022)
    	at kotlinx.coroutines.experimental.JobSupport.completeUpdateState(JobSupport.kt:229)
    	at kotlinx.coroutines.experimental.JobSupport.updateState(JobSupport.kt:157)
    	at kotlinx.coroutines.experimental.JobSupport.makeCompletingInternal(JobSupport.kt:568)
    	at kotlinx.coroutines.experimental.JobSupport.makeCompletingOnce$kotlinx_coroutines_core(JobSupport.kt:552)
    	at kotlinx.coroutines.experimental.AbstractCoroutine.resume(AbstractCoroutine.kt:103)
    	at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:41)
    	at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:41)
    	at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:41)
    	at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:41)
    	at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:41)
    	at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:41)
    	at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:41)
    	at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:41)
    	at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:41)
    	at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:41)
    	at kotlinx.coroutines.experimental.DispatchedTask$DefaultImpls.run(Dispatched.kt:150)
    	at kotlinx.coroutines.experimental.AbstractContinuation.run(AbstractContinuation.kt:19)
    	at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402)
    	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    	at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
    	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
    Caused by: java.lang.NoClassDefFoundError: kotlinx/serialization/json/JSON
    	at com.khairilushan.mpp.datasource.ProjectDataSource$Network$searchProject$$inlined$requestJson$1.invoke(NetworkService.kt:59)
    	at com.khairilushan.mpp.datasource.ProjectDataSource$Network$searchProject$$inlined$requestJson$1.invoke(NetworkService.kt:10)
    	at io.ktor.common.client.Promise.complete(utils.kt:20)
    	at io.ktor.common.client.JvmUtilsKt$promise$$inlined$also$lambda$1.invoke(JvmUtils.kt:13)
    	at io.ktor.common.client.JvmUtilsKt$promise$$inlined$also$lambda$1.invoke(JvmUtils.kt)
    	at kotlinx.coroutines.experimental.InvokeOnCompletion.invoke(JobSupport.kt:906)
    	at kotlinx.coroutines.experimental.JobSupport.notifyCompletion(JobSupport.kt:1018)
    	... 22 more
    Caused by: java.lang.ClassNotFoundException: kotlinx.serialization.json.JSON
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    	... 29 more
    k
    • 2
    • 11
  • a

    apomelov

    08/09/2018, 10:49 AM
    Hi. Just started with kotlinx.serialization, found the limitation on constructor parameters. It's actually makes impossible to use inheritance and I'm looking for ways to work around this. One of my attempts was to make parent's property open and override it in child. Like this:
    @Serializable
    abstract class Tree(open val health: Int = 100)
    
    @Serializable
    class Willow(override val health: Int = 95) : Tree(health)
    But I was surprised when saw the JSON:
    ["Willow",{"health":95,"health":95}]
    Actually, I'm not sure it's a valid one... How can I handle inheritance with serialization?
    s
    j
    +2
    • 5
    • 20
  • v

    vpriscan

    08/15/2018, 11:32 AM
    how to ignore null fields when serializing?
    s
    v
    • 3
    • 3
  • v

    vpriscan

    08/15/2018, 2:01 PM
    I have a question on custom deserializer. If I am expecting either a String or an object when deserializing input, is the following code the way to go:
    fun load(input: KInput): MyObject {
        val maybeString = input.readNullable(StringSerializer)
        return if (maybeString != null) {
            //do something with string that results in creating of MyObject
        } else {
            input.read<MyObject>()
        }
    }
    s
    • 2
    • 2
  • a

    alex009

    08/16/2018, 5:35 AM
    hi. In Kotlin/Native i can use only JsonParser class, without automatic parsing String -> Object ?
    s
    • 2
    • 1
  • a

    Albert

    08/16/2018, 9:49 AM
    I am a bit lost. I am trying to make a custom KSerializer for an object which is a third party entity. Effectively I want to achieve writing
    Map<String, Any>
    but I can't not find how. I tried a specific implementation for that particular class like so:
    output.write(
                    (StringSerializer to StringSerializer).map,
                    mapOf(
                            "access_token" to obj.accessToken,
                            "token_type" to obj.tokenType
                    )
            )
    
            output.write(
                    (StringSerializer to IntSerializer).map,
                    mapOf(
                            "expires_in" to obj.expiresIn
                    )
            )
    But this results into 2 JSON documents. I have the feeling I am overlooking a particular
    Serializer
    s
    • 2
    • 4
  • m

    Mohit Gurumukhani

    08/20/2018, 9:28 PM
    I am kinda confused about using Json-Parser on Kotlin-Native to serialize and deserialize a data class. Are there any samples or resources for this?
    t
    v
    • 3
    • 7
  • m

    Mohit Gurumukhani

    08/23/2018, 9:00 PM
    I am using json-parser in common code to share with native and am getting stack size becomes negative error message with proguard rules. The only way the build succeeds is by adding
    -keep class kotlinx.serialization.json.*
    to proguard-rules.pro. Is this intended? Or is there a better way?
    v
    • 2
    • 1
  • g

    grandstaish

    09/10/2018, 10:08 AM
    Is it necessary that properties without backing fields are serialized?
    k
    s
    • 3
    • 5
  • n

    Nikky

    09/10/2018, 10:27 PM
    seems like JSON does not support
    writeStringElementValue
    or similar, i hoped to be able to use the infrastructure to support writing customized JSON objects
    s
    • 2
    • 6
  • n

    Nikky

    09/12/2018, 11:33 AM
    so seems like
    serializerByTypeToken
    does not work on parameterized types because it passes the wildcardtype on to the next (recursive) call for my ktor PR i fixed it like so: https://github.com/NikkyAI/ktor/blob/2ace29d5478d6f51278b47934884858f17e78c00/ktor-client/ktor-client-features/ktor-client-json/ktor-client-json-jvm/src/io/ktor/client/features/json/serializer/SerialHelperJvm.kt#L24-L29 should i make a PR for this ?
    s
    • 2
    • 2
  • n

    Nikky

    09/12/2018, 9:54 PM
    @Optional is evidently already aware of the default values, so could it be exanded to include this functionality ?
    :thread-please: 1
    s
    • 2
    • 3
Powered by Linen
Title
n

Nikky

09/12/2018, 9:54 PM
@Optional is evidently already aware of the default values, so could it be exanded to include this functionality ?
:thread-please: 1
s

sandwwraith

09/13/2018, 9:03 AM
Currently there is no such option. It will be introduced in a few releases
➕ 1
n

Nikky

09/13/2018, 10:33 AM
is it available in some branch or as pre-release by chance ? for now implemented it manually for data classes with 30 `var`s, now i cannot change thm without adjusting all that (but i confirmed it works)
s

sandwwraith

09/13/2018, 10:57 AM
no, unfortunately it is not implemented yet
View count: 5