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

    themishkun

    06/11/2019, 1:19 PM
    Hello! I’m getting this stacktrace when trying to deserialize my model. It is in proto3 format, but has no
    packed
    fields and all fields in data class are nullable or provided with defaults. Any tips?
    Stacktrace.txt
    s
    t
    • 3
    • 2
  • t

    tylerwilson

    06/13/2019, 1:24 AM
    Issue: using Kotlinx serialization in AppCode, in a class that is marked Serializable, the serialize method that should be generated by the compiler is not found when building the iOS Framework. Known issue? Any fix I can apply?
    s
    • 2
    • 2
  • d

    David

    06/13/2019, 9:42 AM
    similar to @Nikky above I am a bit stumped where to go next when an api response either empty object
    {}
    or the structure that my serialiser expects e.g.
    {"id": "ABC123", "status": "STATUS"}
    . I have tried a number of approaches that i’ve documented on this SO ticket; https://stackoverflow.com/questions/56541201/parsing-empty-object-with-kotlinx-serialization Would anyone be able to point out where I am going wrong?
    l
    s
    n
    • 4
    • 19
  • t

    Toddobryan

    06/13/2019, 4:07 PM
    Is there a way to override the
    encodeDefaults
    value for a given field? I have a
    type
    field that I'm using to distinguish subclasses. Obviously, I set the val in each subclass, but when I'm deserializing, I only know it's the superclass and without the
    type
    , there's no way to know which subclass to deserialize to.
    • 1
    • 1
  • p

    Paulius Ruminas

    06/18/2019, 2:12 PM
    Hi, I have encountered an error because of discriminator field name clash:
    sealed class A {
    
        @Serializable
        data class B(val type: String) : A()
    }
    
    @Test
    fun main() {
        val json = Json(
            configuration = JsonConfiguration.Common,
            context = SerializersModule {
                polymorphic<A> {
                    addSubclass<A.B>()
                }
            }
        )
    
        val s = PolymorphicSerializer(A::class)
        val j = json.stringify(s, A.B(type = "Test"))
    
        json.parse(s, j)
    }
    The code will produce error:
    Test is not registered for polymorphic serialization in the scope of class A
    The error occurs because there are two
    type
    fields. If it is possible it would be nice that this name clash issue would be reported at compile time or if it is not possible I think there should be a better error message that states that one has two
    type
    fields and it is impossible to resolve the polymorphic type. What do you think?
    s
    • 2
    • 1
  • m

    Marc Knaup

    06/19/2019, 3:15 PM
    On that note - what is the reason that the discriminator field name is set globally rather than on a per-type/serializer basis? Depending on what model you consume (or produce) it may be necessary to have it named differently for different types.
    s
    v
    • 3
    • 10
  • m

    Marc Knaup

    06/19/2019, 7:03 PM
    Did the structure of
    kotlinx-serialization-runtime
    modules change from
    0.11.0
    to
    0.11.1
    ? Having only a common dependency to
    kotlinx-serialization-runtime:0.11.0
    works. With
    0.11.1
    this doesn't work anymore. It cannot find the classes and the module has no metadata thus Gradle doesn't automatically resolve
    common
    ,
    jvm
    etc.
    t
    s
    • 3
    • 3
  • s

    Shan

    06/19/2019, 9:58 PM
    Hey all, getting my feet wet with Kotlinx Serialization and have a question: if I have an API request (in JSON) form which I only need, say, 3 primitives from for my usecase, what is the best practice way to define a @ Serializable data class to process this request? Do I have to generate a data class with every possibly entry and set default values, or can I just make a data class that only has the primitives I need and process it before the data class is generated somehow?
    u
    • 2
    • 2
  • s

    sandwwraith

    06/20/2019, 9:46 AM
    📣 kotlinx.serialization
    0.11.1
    has been released. This release is binary compatible with Kotlin/Native 1.3.40. This is mostly a patch release, see notes here: https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md#v0111--2019-06-19
    🎉 10
    r
    b
    • 3
    • 4
  • r

    Robert Jaros

    06/20/2019, 10:26 PM
    After upgrade to 0.11.1 I have problems resolving
    kotlinx-serialization-runtime-js
    module. I've noticed the
    kotlinx-serialization-runtime-js-0.11.1.jar
    contains
    kotlinx-serialization-kotlinx-serialization-runtime.js
    file and the previous
    kotlinx-serialization-runtime-js-0.11.0.jar
    contains
    kotlinx-serialization-runtime.js
    file. Is it intentional or is it a bug?
    s
    b
    • 3
    • 11
  • r

    ribesg

    06/25/2019, 8:44 AM
    How do I serialize/deserialize to/from a simple String using
    kotlinx.serialization
    ?
    t
    • 2
    • 3
  • f

    Fudge

    06/26/2019, 5:14 PM
    @Serializable
    class Wrapper(val test : Test)
    
    enum class Test {
        @SerialName("Bar")
        Foo
    }
      println(json.stringify(Wrapper.serializer(), Wrapper(Test.Foo)))
    This prints
    {test: "Foo"}
    , I would've expected
    {test: "Bar"}
    though, what am I doing wrong?
    g
    • 2
    • 2
  • t

    Toddobryan

    06/27/2019, 6:12 AM
    I think I found a bug.
    JsonElement.booleanOrNull
    doesn't check to see whether
    isString
    is true, so
    parse("true").booleanOrNull
    and
    parse("\"true\"").booleanOrNull
    both return
    true
    , even though I think the secord one should return
    null
    .
    s
    • 2
    • 1
  • f

    Fudge

    06/27/2019, 7:59 AM
    Is there a built-in serializer to "inline" singular-field classes? Example:
    @Serializable(InlineSerializer::class)
        class Inlined(val str :String)
    
       fun main(){
            val obj = Inlined("test")
            val str = json.stringify(Inlined.serializer(),obj)
            assertEquals("\"test\"",str) // And not {"str":"test"}
       }
    t
    p
    • 3
    • 5
  • t

    tylerwilson

    06/29/2019, 3:46 PM
    I need some help. I am trying to set up a custom annotation that will allow me to set a data format value for the my external parser to use. Something like seen here, but with a customizable format (https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/custom_serializers.md#external-serializers-for-library-classes). My goal data declaration would be something like:
    class MyObject {
       @Format("mm/dd/yyyy")
       @Serializable(with = MyDateSerializer::class)
      val poorlyFormattedDate: Date
    }
    Any way to get the Format data from within the MyDateSerializer (without writing a whole custom parsing class for every model in my app/library? Thank you!
    l
    • 2
    • 3
  • a

    altavir

    07/06/2019, 2:18 PM
    I am trying to find an example of working Polymorphic serialization with sealed class hierarchy and for now found only some scraps in commit history of kotlinx.serialization. Do anybody have a reference. My class hierarchy looks like this https://pastebin.com/59usEBxS and I need to have a List of those, which will be transformed into XML (via @pdvrieze plugin) and read back depending on tag name.
    p
    • 2
    • 3
  • f

    Fudge

    07/10/2019, 8:40 AM
    Is there a way to pretty-print a
    JsonObject
    in kotlinx.serialization ?
    r
    a
    • 3
    • 3
  • r

    Rostislav Utrobin

    07/12/2019, 9:11 AM
    When kotlinx.serialization support (to CBOR format) for native (ios) is expected?
    s
    • 2
    • 1
  • t

    thana

    07/14/2019, 3:38 PM
    is there any way to debug bad bytecode generated by the serialization plugin?
    ➕ 1
    s
    • 2
    • 2
  • e

    efemoney

    07/14/2019, 8:13 PM
    I don’t how to repro this but I had an issue uploading a build of my app to the Google playstore and it turned out to be a problem with applying the serialization plugin. In my case, I applied the serialization plugin to an android library module that the main app module depended on and uploading the app to the google play store failed with “some parts of the apk were not signed correctly” (paraphrasing)
    s
    l
    • 3
    • 9
  • p

    PHondogo

    07/15/2019, 6:20 AM
    Hello! Does inheritance supported? For example: class A { .... } class B : A { .... } val a : A = deserialize(serialize(B())) // a has runtime type of B
    s
    • 2
    • 1
  • t

    Toddobryan

    07/15/2019, 11:06 PM
    Where does the code that does the annotation processing live in the serialization repo? I can't find it anywhere?
    j
    s
    • 3
    • 8
  • w

    william

    07/16/2019, 3:38 AM
    are there any android libraries that work with androidx serialization out of the box?
    i
    p
    • 3
    • 5
  • p

    Paulius Ruminas

    07/16/2019, 6:33 PM
    Hello, currently I'm using
    PolymorphicSerializer
    for sealed class like this
    @Serializable(PolymorphicSerializer::class)
    sealed class Response {
    
        @Serializable
        data class Success(val token: Token) : Response()
            
        // serializer defined in serial module
        object Failure : Response()
    }
    I found this section in doc comment of
    @Polymorphic
    annotation.
    Does not affect sealed classes, because they are gonna be serialized with subclasses automatically with special compiler plugin support which would be added later.
    At first I thought I could use
    @Polymorphic
    instead of
    @Serializable(PolymorphicSerializer::class)
    but it does not work that way. Will this approach change in the future?
    s
    p
    • 3
    • 5
  • a

    alex009

    07/18/2019, 12:39 PM
    hi all! can anyone help me with enum serialization? i have enum values 1,2,3,4 and write this enum:
    enum class Status {
        @SerialName("1")
        ACTIVE,
        @SerialName("2")
        BLOCKED,
        @SerialName("3")
        WAIT_UPDATE_PROFILE,
        @SerialName("4")
        WAIT_APPROVE;
    }
    but serialization can't parse Status:
    kotlinx.serialization.SerializationException: com.icerockdev.generated.ktor.models.RelativeProfileResponse.Status does not contain element with name '1'
    enums not support
    @SerialName
    ?
    s
    • 2
    • 4
  • s

    serebit

    07/18/2019, 9:44 PM
    Configuring polymorphic serialization by tag/ID is proving surprisingly difficult due to the lack of documentation. Are there any resources I should look at?
    d
    • 2
    • 4
  • v

    v79

    07/20/2019, 10:16 AM
    Just getting my grips with kotlinx.serialization. If I have a class
    MDCacheItem
    which is
    @Serializable
    (and I do, I've got that working fine and have written custom serializers), what do I need to do to serialize a
    Set<MDCacheItem>
    ?
    val jsonData = json.stringify(MDCacheItem.serializer(), setToCache)
    is not allowed.
    s
    • 2
    • 2
  • t

    turansky

    07/22/2019, 9:42 PM
    Inline class serialization/deserialization doesn’t work in
    1.3.50-eap-5
    even with custom serializer.
    @Serializable(with=KeySerializer::class)
    inline class Key(val source:String)
    Error:
    Inline class serialization not supported
    No problem in
    1.3.41
    . Is it planned regression for
    1.3.50
    ?
    :yes: 1
    👍 1
    s
    i
    p
    • 4
    • 9
  • m

    mathew murphy

    07/23/2019, 7:25 PM
    @serebit So I was also having problems getting polymorphic deserialization to work, using Moshi. I switched to Klaxon and got it working without too much trouble. Just something to consider if you still didn't get it working.
    s
    • 2
    • 1
  • j

    Jan Stoltman

    07/28/2019, 6:15 AM
    I'm trying to parse a Json in a backthread on native using kotlinx.serializer, but it fails with InvalidMutability exception. it used to work just fine with kotlin 1.3.30 and serialization 10.0 but fails at 1.3.41/11.1. Do you guys know if anything important changed in serialization between these two versions?
    s
    • 2
    • 3
Powered by Linen
Title
j

Jan Stoltman

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

sandwwraith

07/29/2019, 9:04 AM
There was https://github.com/Kotlin/kotlinx.serialization/issues/441, but it was in 11.0 and fixed in 11.1
You can file a new bug if you'd like
j

Jan Stoltman

07/29/2019, 1:55 PM
That's exactly what I'm looking for, thanks
View count: 5