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

    Michał Kalinowski

    02/12/2020, 7:03 PM
    I already try make generics for it, but adding ImplicitReflectionSerializer annotation for each method looks so bad 😞
    Untitled
    d
    s
    • 3
    • 4
  • s

    Sam

    02/14/2020, 2:17 PM
    I need to consume a jsonapi (https://jsonapi.org) based endpoint and looking for some pointers on how to get started deserializing the data. I have a basic response with serializer attributes setup but it isn’t quite right. >>>
    b
    d
    +2
    • 5
    • 12
  • u

    ursus

    02/15/2020, 10:28 PM
    Hi, im trying to hack android sqlite to store unnormalized data via json, (because reasons..) and now im wondering if I should use protobuf blobs instead of json
    d
    • 2
    • 3
  • c

    camkadev

    02/17/2020, 11:44 AM
    kotlin/native serialization
    Cannot infer type parameter
    what should i do at
    Serializer
    line
    31
    ? https://github.com/AlexanderShniperson/KotlinNativeSerialization
    • 1
    • 1
  • r

    ribesg

    02/18/2020, 1:41 PM
    What’s the Gradle task to generate serializers? I don’t see it in IDEA nor in the result of
    gradle tasks
    , but I do have the plugin
    kotlin("plugin.serialization")
    and everything compiles. It’s just that I don’t see them in IDEA
    e
    s
    • 3
    • 25
  • t

    Trond Tunheim

    02/19/2020, 9:34 AM
    I'm using kotlinx serialization and have run into a strange problem. When i compile and run the code in DEBUG mode it works fine as expected, but when i compile the same code in RELEASE i get an exception. The code where the exception occurs is shown here :
    val json = Json(JsonConfiguration.Stable)
    var testJson = json.parse<JobInit>("{\"jobId\":\"j8203f1c50abe46338fa4d8955405949e\",\"jobStatus\":\"JobSubmitted\"}")
    @Serializable
    data class JobInit (val jobId : String = "", val jobStatus : String ="")
    When running in RELEASE I get the following exception : Uncaught Kotlin exception: kotlinx.serialization.json.JsonDecodingException: Invalid JSON at 0: Expected '[, kind: LIST' Anyone else had this problem or know what is wrong ? I'm using "org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:0.14.0"
    s
    • 2
    • 1
  • r

    ross_a

    02/22/2020, 11:09 AM
    Hello, has anyone had any experience replacing Jackson with kotlinx.serialization in a Spring Boot project?
    v
    s
    s
    • 4
    • 5
  • r

    Rodrigo Silva

    02/25/2020, 1:57 AM
    Hi all. I'm getting a hard time trying to use kotlinx serialization with ktor. how do I serialize / deserialize an Any attribute (which can be any class)? Stackoverflow question https://stackoverflow.com/questions/60399691/changing-jackson-to-kotlinx-using-ktor
    d
    • 2
    • 9
  • a

    altavir

    02/26/2020, 9:05 AM
    Is it possible to somehow add pre-deserialization hooks? I just found that some of my input data has string expressions in places, where numbers should be. I can evaluate them, but I do not want to violate a scheme for that.
    t
    s
    • 3
    • 3
  • t

    turansky

    02/26/2020, 4:50 PM
    Is it possible to analyze if
    obj
    in
    DynamicInput
    has some properties? https://github.com/Kotlin/kotlinx.serialization/blob/3dc46736406bd6c4c16680b275194f27c2bf360e/runtime/jsMain/src/kotlinx/serialization/DynamicObjectParser.kt#L27
    s
    • 2
    • 4
  • s

    suresh

    02/26/2020, 6:03 PM
    Hi, is there way to access the serializer() companion object in a generic way with a reified type? I checked the generated
    Serializable
    class to see if there is a any common interface. What i am doing is,
    @Serializable
    data class TT(
        val ciId: Long = -1,
        val ciAttributes: Map<String, String?> = emptyMap()
    ) {
        inline fun <reified T> asType(serializer: KSerializer<T>): T {
            return Mapper.unmapNullable(serializer, ciAttributes)
        }
    
    }
    
    val t: TT = ....
    val x = t.asType(XX.serializer())
    r
    s
    • 3
    • 6
  • k

    Kristian

    03/02/2020, 6:21 PM
    I know that type erasure is the cause of the issue but i am not sure how to solve it with the ktor feature version of kotlinx serialization. Any tips would be much appreciated
    s
    e
    • 3
    • 4
  • t

    turansky

    03/03/2020, 9:38 PM
    There is no
    .serializer()
    for primitives in
    eap-274-2
    😞
    s
    • 2
    • 1
  • s

    sandwwraith

    03/04/2020, 4:35 PM
    📣 kotlinx.serialization
    0.20.0
    has been released! This release is compatible only with Kotlin 1.3.70. It is focused on giving a library its final and stable API shape, so we took the liberty to introduce minor breaking changes in order to give users the better, more convenient API. Highlights: • Some declarations were deprecated because they are going to be replaced with others, e.g. top-level
    IntSerializer
    object was replaced with
    Int.serializer()
    extension function for consistency. • Json's
    strictMode
    flag is deprecated and replaced with 3 other flags, thus allowing to fine-tune settings. • Protobuf, Cbor and Mapper were extracted to separate artifacts to keep the core API lightweight. • A lot of bugs fixed and a lot of entities documented • Shiny new feature — json-specific transofrming serializers: instead of manipulating calls to
    Encoder
    and
    Decoder
    directly, one can write serializer using pure JSON AST manipulations. Learn more here: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/json_transformations.md Full release note with a list of deprecations, migration guides and fixed bugs is available in changelog: https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md#0200--2020-03-04
    :kotlin: 2
    👍 26
    t
    g
    • 3
    • 2
  • t

    tylerwilson

    03/04/2020, 8:02 PM
    So while updating to 0.20, I had to make some changes to some customer serializers I had written, which highlighted the fact that I am unclear what the SerialDescriptor is actually used for, and how best to define it. So I would like those more knowledgeable to look at my code and tell me what I might be doing wrong, if anything (it currently appears to working fine [it is only used for input]). I am dealing with JSON that includes boolean values as true/false, “Y”/“N”, “0”/“1" or “true”/“false”. So I have the following:
    @Serializer(forClass = Boolean::class)
    object BooleanSerializer: KSerializer<Boolean> {
    
        override val descriptor: SerialDescriptor = //StringDescriptor.withName("Format")
            PrimitiveDescriptor("BooleanSerializer", PrimitiveKind.BOOLEAN)
    
        override fun serialize(encoder: Encoder, obj: Boolean) {
            encoder.encodeInt(if (obj) 1 else 0)
        }
    
        override fun deserialize(decoder: Decoder): Boolean {
            val stringValue = decoder.decodeString()
            return stringValue == "Y" || stringValue == "1" || stringValue == "true"
        }
    }
    You can see the old definition for the descriptor of StringDescriptor, but I changed it to a PrimitiveDescriptor. I am still unclear what I should give as the serialName (does it include the package name, or just any name we want) and the PrimitiveKind (should this be a Boolean or a String in this case). Thank you to anyone who can edify me.
    v
    • 2
    • 4
  • t

    tylerwilson

    03/04/2020, 9:47 PM
    And one more: this one handles the case where we expect an array, but instead we get a single object. So instead of:
    items: [ { }, {} ]
    we get:
    items: { }
    This will allow us to always treat it as an array.
    Untitled
    s
    p
    • 3
    • 6
  • t

    thana

    03/05/2020, 9:01 AM
    class java.util.TreeMap is not registered for polymorphic serialization in the scope of class java.util.NavigableMap
    is there an easy way to fix that? bascally im fine with the TreeMap getting serialized as any other map...
    v
    • 2
    • 3
  • j

    Jan Stoltman

    03/05/2020, 12:47 PM
    Hey, when serializing enums with
    Serializable
    annotation is there any way to provide default value other than writing custom serializer?
    t
    • 2
    • 2
  • r

    Robert Jaros

    03/05/2020, 2:38 PM
    Mapper
    was changed to
    Properties
    but are there any other internal changes in this class? I get NPE when trying to use it the same way as in 1.3.61 ?
    • 1
    • 3
  • s

    Sam

    03/05/2020, 9:10 PM
    I have a tree structure that looks like:
    ["a", "b", "c", {
    	"i": 1,
    	"id": "d"
    }, {
    	"i": 2,
    	"id": "e"
    }]
    How would I go about deserializing this? I would like the items of the array to to be one of two sealed class types
    Entry
    and
    Folder
    . In the example above, the a, b & c values would be assigned to an
    id
    property on
    Entry
    .
    Folder
    is simple enough to map. I already have a class to handle the top level array. The trouble I’m having is figuring out how to do a custom serializer for the sealed class containing Entry and Folder.
    d
    • 2
    • 2
  • c

    coletz

    03/05/2020, 9:54 PM
    hi guys, I am experiencing a strange issue. I am using serialization lib in order to parse a json string; it's a simple object with a list inside (
    {data: [{..},{..}]}
    ); it works fine on android, while on iOS all the values inside the list are null. The external
    data
    object is parsed and the list too, but all the objects in the list have every value setted to null
    • 1
    • 4
  • r

    russhwolf

    03/06/2020, 3:01 AM
    In 0.20.0, `NamedValueEncoder`/`Decoder` are marked
    @InternalSerializationApi
    . Will that remain the case in 1.0? If so, what should custom formats be using instead?
    v
    • 2
    • 3
  • r

    russhwolf

    03/06/2020, 3:58 AM
    Also, what’s the roadmap for missing native targets? I see some new ones have been added, but the androidNative and linuxMips ones still aren’t present.
    s
    • 2
    • 2
  • p

    Paulius Ruminas

    03/06/2020, 10:13 AM
    Hello, I have migrated to 0.20.0 and I'm getting the following error:
    Using 'SerialClassDescImpl' is an error. Should not be used in general code, please migrate to SerialDescriptor() factory function instead
    How do I migrate to
    SerialDescriptor()
    factory? I can not find such a method. I can only see
    kotlinx.serialization.SerialDescriptor
    interface.
    t
    • 2
    • 3
  • c

    CLOVIS

    03/06/2020, 6:24 PM
    Hi! I have the current code:
    @Serializable
    private data class ApiUsernamePassword(val username: String, val password: String)
    I use Ktor (it handles serialization itself). On Kotlin/JVM, the code runs fine, but on Kotlin/JS I get:
    SerializationException: Can't locate argument-less serializer for class ApiUsernamePassword. For generic classes, such as lists, please provide serializer explicitly.
    	at <global>.serializer([REDACTED]/runtime/commonMain/src/kotlinx/serialization/PlatformUtils.kt:12)
    I use version 0.14.0 of the serialization plugin, with Kotlin 1.3.61 and Gradle 6.0.1
    t
    • 2
    • 5
  • c

    CLOVIS

    03/06/2020, 6:55 PM
    Edited the message to feature the correct Kotlin version, but the problem is still there...
    t
    • 2
    • 3
  • m

    Michał Kalinowski

    03/08/2020, 7:38 AM
    Hey, so maybe someone know why with this code:
    @Serializable
    data class SerializableTransformation(
      val translateX: Float = 0f,
      val translateY: Float = 0f,
      val rotateY: Float = 0f
    )
    kotlinx-serialization give me an exception:
    Exception in thread "main" kotlinx.serialization.MissingFieldException: Field 'rotateY' is required, but it was missing
    I thought that default values make fields optional for serialization, but maybe I'm wrong Thanks in advance :kotlin-flag:
    r
    p
    t
    • 4
    • 7
  • i

    Ivann Ruiz

    03/09/2020, 12:28 AM
    Just a heads up, this weekend I tried starting a multiplatform project using kotlinx.serialization library and just couldn't figure out how to get it to serialize a response. I kept having the error I show below. I suspect it has something to do with the versions of the libraries I was using. I know that if you're using
    Kotlin plugin version 1.3.70
    you MUST use
    kotlinx.serialization version 0.20.0
    because it's NOT backwards compatible. Spent a whole day stuck, finally ended up reverting back to
    Kotlin plugin 1.3.61
    and
    kotlinx.serialization 0.14.0
    and it finally worked. Also used
    ktor 1.3.1
    . Just wondering if anybody has tried using the
    kotlinx.serialization
    library with
    Kotlin 1.3.70
    successfully? Here's a GitHub gist: https://gist.github.com/lamvann/d441b2529d4f3b164edc5947401a1e4f
    E/AndroidRuntime: FATAL EXCEPTION: main
        Process: org.jetbrains.kotlin.mpp_app_android, PID: 28267
        java.lang.NoSuchFieldError: No field Companion of type Lkotlinx/serialization/json/Json$Companion; in class Lkotlinx/serialization/json/Json; or its superclasses (declaration of 'kotlinx.serialization.json.Json' appears in /data/app/org.jetbrains.kotlin.mpp_app_android-InBSbzMi00a168C538jy0g==/base.apk)
            at io.ktor.client.features.json.serializer.KotlinxSerializer.<init>(KotlinxSerializer.kt:22)
    r
    r
    c
    • 4
    • 5
  • s

    Sebastien Leclerc Lavallee

    03/09/2020, 7:52 PM
    Let say I have a class:
    @Serializable
    data class SomeClass(val a: Int)
    And a function that can receive pretty much everythin:
    fun someFunction(object: Any)
    How can I check that the function’s parameter is Serializable? I did try something like:
    when (object) {
       is Serializable -> doSomething()
    }
    But that doesn’t work. Someone has some lights to help me?
    c
    r
    • 3
    • 3
  • i

    ivan.savytskyi

    03/10/2020, 5:51 PM
    hey folks, I ran into issue after migrating to `0.20.0`:
    java.lang.NoSuchMethodError: No direct method <init>(Ljava/lang/String;Lkotlinx/serialization/internal/GeneratedSerializer;I)V in class Lkotlinx/serialization/internal/SerialClassDescImpl; or its super classes (declaration of 'kotlinx.serialization.internal.SerialClassDescImpl' appears in ....)
    . Am I missing any migration steps? Found similar issue: https://github.com/Kotlin/kotlinx.serialization/issues/736 that still reproduces for me
    t
    m
    • 3
    • 7
Powered by Linen
Title
i

ivan.savytskyi

03/10/2020, 5:51 PM
hey folks, I ran into issue after migrating to `0.20.0`:
java.lang.NoSuchMethodError: No direct method <init>(Ljava/lang/String;Lkotlinx/serialization/internal/GeneratedSerializer;I)V in class Lkotlinx/serialization/internal/SerialClassDescImpl; or its super classes (declaration of 'kotlinx.serialization.internal.SerialClassDescImpl' appears in ....)
. Am I missing any migration steps? Found similar issue: https://github.com/Kotlin/kotlinx.serialization/issues/736 that still reproduces for me
t

turansky

03/10/2020, 8:57 PM
Do you have isolated project?
m

Marc Knaup

03/11/2020, 7:55 AM
Have you also updated Kotlin to 1.3.70?
t

turansky

03/11/2020, 9:32 AM
With all dependencies, which use serialization
i

ivan.savytskyi

03/11/2020, 5:11 PM
Have you also updated Kotlin to 1.3.70
Yes
Do you have isolated project?
Unfortunately no
With all dependencies, which use serialization
Will double check that
t

turansky

03/11/2020, 5:21 PM
Full sync required for serialization 😞
i

ivan.savytskyi

03/11/2020, 5:24 PM
I found that we missed coroutines dependency that was 1.3.3
testing if that was the culprit
View count: 6