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

    charleskorn

    01/31/2019, 9:29 AM
    Anyone else seeing errors like this after upgrading to Kotlin 1.3.20? The class it’s trying to generate a serializer for has a custom serializer defined within it (code is at https://github.com/charleskorn/batect/blob/master/app/src/main/kotlin/batect/os/Command.kt)
    -.txt
    s
    w
    12 replies · 3 participants
  • g

    ghedeon

    01/31/2019, 1:35 PM
    This prints `{"bar":"lorem"}`:
    @Serializable
    	data class Foo(@Transient val bar: String)
    	
    	println(Json.stringify(Foo.serializer(), Foo("lorem")))
    Do I miss anything about
    @Transient
    ?
    s
    2 replies · 2 participants
  • n

    Narek Mailian

    01/31/2019, 3:07 PM
    Hi people, I'm really not getting serialization to work in my multi-platform kotlin-native project. I'm just getting "unresolved reference: serializer" and gradle refuses to compile. Is this even supported or am I just doing something wrong? Example code available at: https://github.com/rundfunk47/MultiPlatformSerialization
    t
    2 replies · 2 participants
  • n

    Narek Mailian

    02/01/2019, 12:21 PM
    Maybe a bit of a stupid question, but being from a Swift background: Can anyone help me to get this code using a generic argument
    T
    instead of
    Data
    ?
    fun deserialize(string: String): Data {
            return Json.nonstrict.parse(Data.serializer(), string)
        }
    j
    5 replies · 2 participants
  • j

    josephivie

    02/01/2019, 10:35 PM
    I'd like to introduce a new extension to KotlinX Serialization: Mirror! https://github.com/lightningkite/mirror-kotlin It's an independent plugin for KotlinX Serialization that also adds some reflective functionality. Polymorphism works for all platforms, and annotations have been entirely replaced with a manifest file. The plugin can also read directly from your common dependencies, allowing you to easily serialize things from your libraries as well.
    👍 2
    1 reply · 1 participant
  • m

    max.cruz

    02/01/2019, 10:52 PM
    Hi guys. I have a question. I’m working on a multiplatform project with a common module sharing code between Android/iOS. In the common module, I have some model classes annotated with @Serialization. With Android, everything works as is expected, but when I try to generate the library for iOS I get this error:
    > Task :common:compileKotlinIos
    error: compilation failed: Can’t locate polymorphic serializer definition
    (gradle 4.10.3, kotlin 1.3.20, kotlinx-serialization-runtime-native 0.9.1) There is some workaround or suggestion to fix this issue?
    j
    s
    5 replies · 3 participants
  • g

    ghedeon

    02/01/2019, 10:56 PM
    When working with custom serializers, do you really need to provide separate ones for the type itself and for the collection of this type? ex:
    @Serializable(with = FooSerializer::class)
     val names: List<Foo>
    Works only if I define
    FooSerializer: KSerializer<List<Foo>>
    . I'm wondering if I can define only
    FooSerializer: KSerializer<Foo>
    and let the kotlin to deal with collections.
    👍 1
    m
    3 replies · 2 participants
  • g

    ghedeon

    02/02/2019, 10:56 AM
    To clarify, the performance of : 1.
    @ContextualSerialization
    on a file 2.
    @Serializable(with =)
    on a field 3.
    Json.install()
    is the same? It's 3 different ways of runtime resolution?
    s
    n
    4 replies · 3 participants
  • g

    galex

    02/06/2019, 5:08 AM
    Hello, I’ve applied the plugin, added dependencies in an MPP and annotated any class I send with @Serializable. I’ve got a response in the format of Response<SomeModel> to parse in kotlin js (node). The error I get is the following:
    TypeError: tmp$.serializer is not a function at compiledSerializer (<http://localhost:9000/bundle.js:44171:87>) at serializer (<http://localhost:9000/bundle.js:36889:22>) at KotlinxSerializer.lookupSerializerByType_0 (<http://localhost:9000/bundle.js:54654:64>) at Coroutine$read_ro165m$.doResume (<http://localhost:9000/bundle.js:54591:40>) at KotlinxSerializer.read_ro165m$ (<http://localhost:9000/bundle.js:54621:21>) at Coroutine$JsonFeature$Feature$install$lambda_0.doResume (<http://localhost:9000/bundle.js:54456:63>) at <http://localhost:9000/bundle.js:54488:21> at SuspendFunctionGun.loop_0 (<http://localhost:9000/bundle.js:62922:16>) at <http://localhost:9000/bundle.js:62879:31> at SuspendFunctionGun.proceed (<http://localhost:9000/bundle.js:62887:49>)
    message: "tmp$.serializer is not a function"
    Any idea? -> Seems like the problem comes from generics? I’ve just tried sending a simple model as response and this worked. So what’s the deal with generics?
    s
    2 replies · 2 participants
  • j

    jw

    02/08/2019, 3:02 PM
    probably not, but it's fairly trivial to write your own. Most of those types produce a canonical representation via
    toString()
    and have a static parser of that representation
    👍 1
    r
    1 reply · 2 participants
  • n

    Nikky

    02/11/2019, 7:26 AM
    make sure you also set
    encodeDefaults = false
    in
    Json
    constructor call
    g
    5 replies · 2 participants
  • b

    bartvh

    02/13/2019, 12:46 PM
    I want to serialize a set of IP addresses. I have created an InetAddressSerializer, but how do I apply it to a set using annotations? I can't use
    (..).set
    in an annotiation.
    @Serializable
    data class SessionState(
            @Serializable(with = InstantSerializer::class)
            val start: Instant,
            val ips: Set<InetAddress>?
    )
    s
    2 replies · 2 participants
  • a

    Akash Agarwal

    02/21/2019, 5:52 PM
    How do I do Json.stringfy on a data class?
    s
    1 reply · 2 participants
  • s

    spand

    02/25/2019, 1:29 PM
    I have
    @Serializable
    class Response(
            val localDate: LocalDate
    )
    
    @Serializable(with = LocalDateSerializer::class)
    expect class LocalDate
    
    @Serializer(LocalDate::class)
    expect object LocalDateSerializer : KSerializer<LocalDate>
    But it complains that no Serializer for element of type LocalDate has been found. Am I doing something wrong ?
    s
    2 replies · 2 participants
  • a

    apomelov

    02/28/2019, 5:45 AM
    Hi there. I'm not following this thread too close, just checking time to time for some features that were blocking me in the past. I've just read the project status at github and failed to find a ticket in youtrack. What is the status of polymorphic collections issue? I need to send a list of abstract items to a client and call some virtual code for each of them.
    s
    3 replies · 2 participants
  • s

    stanislav

    02/28/2019, 8:53 AM
    Hey, I got this error only in iOS project:
    error: compilation failed: Can't locate polymorphic serializer definition
    j
    11 replies · 2 participants
  • p

    Paulius Ruminas

    03/05/2019, 2:14 PM
    Hello, is it possible to serialize objects e.g.
    sealed class Error {
        @Serializable
        data class Fatal(val message: String) : Error()
    
        @Serializable
        object Unauthorized: Error()
    
        @Serializable
        object Forbidden: Error()
    }
    It does not throw an error but it is not the same object if i deserialize it multiple times.
    s
    2 replies · 2 participants
  • j

    josephivie

    03/06/2019, 6:22 PM
    Specifically the
    serialize
    and
    deserialize
    functions. Note that you do need to write your own descriptor that further defines the fields for
    type
    and
    data
    .
    p
    p
    8 replies · 3 participants
  • p

    Patrick Jackson

    03/12/2019, 4:19 PM
    I have a working MPP using ktor with serialization & models in a shared module. Builds and runs on Android, however building to iOS I get some build errors around serialization. Specifically: An operation is not implemented: Serializable classes with inheritance Is there a list of deltas between what is implemented on the different platforms and the status of different features on each platform?
    s
    2 replies · 2 participants
  • m

    Marc Knaup

    03/12/2019, 9:11 PM
    What is the plan regarding improving error handling? E.g. when sending a JSON request to a ktor server all it can do is respond with an error message like
    Strict JSON encountered unknown key: title\nYou can disable strict mode to skip unknown keys
    . That's not very helpful for the developer implementing the API client because they don't know the full JSON path and/or location where the problem has occurred. Also it communicates implementation-specific information in the message which you don't want to report to clients. More useful would be something like
    Unexpected property 'title' in 'request.posts[0].author' at offset 123
    .
    👍 3
    c
    1 reply · 2 participants
  • m

    Marc Knaup

    03/12/2019, 9:27 PM
    Decoding invalid enum values is quite weird 😄
    IllegalStateException: -3 is not among valid MyEnum choices, choices size is 7
    😂 1
    s
    1 reply · 2 participants
  • m

    Marc Knaup

    03/12/2019, 9:29 PM
    Another question: Is it possible to single-step through the generated serializers? Or check out code and variables when going up the stacktrace?
    s
    1 reply · 2 participants
  • r

    ribesg

    03/13/2019, 4:08 PM
    Is there a way to completely prevent the serializer from ever serializing a
    null
    value anywhere?
    s
    d
    +1
    35 replies · 4 participants
  • h

    hallvard

    03/14/2019, 10:00 AM
    Try this, @ribesg: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/custom_serializers.md
    r
    1 reply · 2 participants
  • r

    ribesg

    03/14/2019, 10:23 AM
    I need to deserialize the results of a search query to Algolia. The result object contains a
    hits
    array containing the results of the query. Depending on the index the query was run on, the model of these results change. How do I implement that with
    kotlinx.serialization
    ? - Can I use generics? - Can I use inheritance, with one subclass per model? - Can I say that these results should stay “raw”, like JsonObject or String, and deserialize them later to the correct model?
    q
    3 replies · 2 participants
  • j

    JoakimForslund

    03/22/2019, 2:43 PM
    Does an util/option exist to add backslashes to Json.stringify result?
    r
    2 replies · 2 participants
  • t

    Thomas

    03/25/2019, 8:25 PM
    Are there any plans to add a streaming reader/writer for JSON? Just like JsonReader/JsonWriter in Gson/Moshi? I'm currently using Moshi (only JsonReader/JsonWriter classes) but am looking for a multiplatform solution for Kotlin/Native.
    d
    s
    5 replies · 3 participants
  • p

    Paul Woitaschek

    03/26/2019, 9:24 AM
    Is there anything I would gain by migrating from moshi/gson to kotlin serialization besides multi platform?
    n
    t
    +1
    5 replies · 4 participants
  • c

    Casey Brooks

    03/26/2019, 4:14 PM
    Is it possible to deserialize JSON into its basic untyped structure of just Maps, Lists, and primitives?
    g
    4 replies · 2 participants
  • n

    Nikky

    03/26/2019, 6:07 PM
    so whats the current best solution for this kind of problem?
    "identifier": "fabric:min",
    "value": 10
    "identifier": "fabric:enum",
    "value": ["A", "B", "C"]
    r
    1 reply · 2 participants
Powered by Linen
Title
n

Nikky

03/26/2019, 6:07 PM
so whats the current best solution for this kind of problem?
"identifier": "fabric:min",
"value": 10
"identifier": "fabric:enum",
"value": ["A", "B", "C"]
r

rrader

03/27/2019, 7:53 AM
https://github.com/Kotlin/kotlinx.serialization/issues/403
View count: 3