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

    Ilya Goncharov [JB]

    03/27/2019, 12:37 PM
    Hello, I have data class with Collection, and I want this collection to be non-null, but field is marked as Optional annotation with emptyList default. If JSON contains appropriate field with null value, Exception
    Expected class kotlinx.serialization.json.JsonArray but found class kotlinx.serialization.json.JsonNull
    is thrown. Is it possible to ignore that null value in json?
    • 1
    • 1
  • n

    Nikky

    03/27/2019, 5:34 PM
    so it seems like i cannot parse
    Map<String, List<Field>>
    ,
    Field
    is a custom type the error says just
    > Invalid JSON at 4617: Expected '}'
    the index seems to match up with the end of the file and the json seems correct to me is there any known problems with nesting lists in maps ?
    • 1
    • 1
  • r

    ribesg

    03/28/2019, 9:43 AM
    Is there a way to have a property name different than the json key, other than having a custom serializer?
    g
    • 2
    • 3
  • r

    Rainer Schlonvoigt

    03/29/2019, 9:01 AM
    would like it to return
    {"mandatory":3}
    instead
    t
    r
    • 3
    • 2
  • p

    Paulius Ruminas

    04/03/2019, 7:28 AM
    Hello, i'm trying to write a custom serializer and i'm getting an exception:
    Can't locate argument-less serializer for class kotlinx.serialization.json.JsonObject. For generic classes, such as lists, please provide serializer explicitly.
    @Serializable
        class Foo {
            @Serializer(forClass = Foo::class)
            companion object : KSerializer<Foo> {
    
                override fun serialize(encoder: Encoder, obj: Foo) {
                    encoder.encode(JsonObject::class.serializer(), JsonObject(mapOf("foo" to JsonLiteral("bar"))))
                }
    
                override fun deserialize(decoder: Decoder): Foo {
                    TODO()
                }
            }
        }
    
        fun main() {
            Json.stringify(Foo.serializer(), Foo())
        }
    n
    s
    • 3
    • 16
  • i

    ivan.savytskyi

    04/03/2019, 4:23 PM
    hey folks is there any issue with AS 3.3.1 and
    kotlinx-serialization
    plugin, as it can’t
    .serializer()
    generated function to be resolved? Or there is some conf I missing?
    s
    • 2
    • 7
  • r

    ribesg

    04/04/2019, 8:23 AM
    Is there a not-too-hard way to deserialize an object containing a list of items which may be incorrect without crashing the entire deserialization if one single value of one single item is unexpected? I would just like to ignore this item or something
    k
    • 2
    • 2
  • k

    krtko

    04/06/2019, 6:05 AM
    I'm almost certain I know the answer, but caching the auto generated serializers and using them across theads is totally fine right?
    s
    • 2
    • 2
  • k

    krtko

    04/11/2019, 5:23 AM
    I get the point of having special de/serializers but it would be sweet if annotated objects defaulted to just having a static method that handles the serialization. I would mention I'm loving Kotlins serialization. It's great. I'm also amazed at how well Kotlins plugin annotation system works.
    e
    t
    +2
    • 5
    • 8
  • t

    thevery

    04/12/2019, 7:16 AM
    Is 0.11.0-1.3.30-eap-125 compatible with 1.3.30-release or I should wait a bit for new release?
    s
    • 2
    • 2
  • p

    Paulius Ruminas

    04/12/2019, 11:25 AM
    Hi, I'm using serialization
    0.10.1
    . After update to Kotlin
    1.3.30
    from
    1.3.21
    I get this error:
    e: java.lang.IllegalStateException: Backend Internal error: Exception during code generation
    Cause: org.jetbrains.kotlin.codegen.ErasedInlineClassBodyCodegen cannot be cast to org.jetbrains.kotlin.codegen.ImplementationBodyCodegen
    It's caused by:
    @Serializable(with = TaskIdSerializer::class)
    inline class TaskId(val value: Guid)
    
    @Serializer(forClass = TaskId::class)
    object TaskIdSerializer : KSerializer<TaskId> {
        override fun serialize(encoder: Encoder, obj: TaskId) = encoder.encodeString(obj.value)
        override fun deserialize(decoder: Decoder): TaskId = TaskId(decoder.decodeString())
    }
    Is there a repository with an eap version that I could try?
    s
    • 2
    • 5
  • j

    jw

    04/12/2019, 3:30 PM
    If you're a Retrofit user, version 0.4.0 of retrofit2-kotlinx-serialization-converter was just released supporting 0.11.0 (since it's binary incompatible with 0.10.0)
    :kotlin-flag: 3
    🔥 4
    r
    • 2
    • 3
  • d

    drofwarcs

    04/12/2019, 3:46 PM
    after upgrading to Kotlin 1.3.30 and serialization 0.11.0 I'm running into
    > Task :common:linkDebugFrameworkIos
    e: Compilation failed: org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl@6c61d6d9 not in vtable of org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl@641449e4
    .......
    .......
     * Compiler version info: Konan: 1.2 / Kotlin: 1.3.30
     * Output kind: FRAMEWORK
    .......
    Anything I can do to get around this issue?
    s
    t
    • 3
    • 6
  • f

    fkrauthan

    04/12/2019, 11:01 PM
    Just to double check but
    Polymorphic serialization is now available for JS and Native
    does still not mean that we can serialize a data class to a native JSON object for kotlin JS? (https://github.com/Kotlin/kotlinx.serialization/issues/116)
    s
    • 2
    • 2
  • r

    Robert Jaros

    04/13/2019, 11:53 AM
    I've noticed, that new
    kotlinx-serialization-runtime-js.js
    file for Kotlin/JS is "resistant" to the DCE plugin, even if serialization is not used. It is reduced by DCE from 420KB to 165KB. The old one (0.10.0) is reduced from 374KB to 10KB in the same configuration. This has impact on the size of the output files for Kotlin/JS apps, if the kotlinx.serialization library is present in the sub dependencies, but no serialization features are used. Any idea what is the cause of this behavior? Any chance it can be fixed?
    v
    • 2
    • 2
  • r

    Riccardo Montagnin

    04/15/2019, 9:29 AM
    Hello everyone! Is there an option to force keys to be sorted alphabetically before the serialization?
    r
    s
    • 3
    • 15
  • t

    turansky

    04/15/2019, 9:50 AM
    Is there possibility to specify custom discriminator for class?
    • 1
    • 1
  • a

    Antanas A.

    04/16/2019, 12:18 PM
    Hi, when using directly JsonObject is there any way to detect if a given property is string? and get result? eg val json:JsonObject; json["propertyStr"]?.primitive.stringOrNull ? I can see that there is booleanOrNull doubleOrNull but no stringOrNull, tried toString() but it produces quoted string
    r
    • 2
    • 6
  • r

    Riccardo Montagnin

    04/17/2019, 12:13 PM
    Hello everyone. How can I serialize a
    Map<String, Any>
    ?
    s
    • 2
    • 5
  • s

    Steven

    04/17/2019, 6:28 PM
    Here is an example of what the API sends me:
    Untitled.txt
    r
    • 2
    • 2
  • a

    Antanas A.

    04/18/2019, 8:03 AM
    Hi, Is it possible to enumerate all classes which contain
    Serializable
    annotation at runtime? Maybe kotlin serializer stores this information in some hash map which can be accessed? I want find an appropriate serializer by knowing only full class name, or this can be done using reflection only?
    c
    • 2
    • 2
  • r

    ribesg

    04/19/2019, 10:19 AM
    Is there a way to obfuscate some fields when serializing a model for logging?
    n
    r
    r
    • 4
    • 6
  • p

    pardom

    04/23/2019, 8:35 PM
    Perhaps this?
    setListMapper(Long::class, Long.serializer())
    k
    s
    • 3
    • 5
  • k

    Konstantin Tskhovrebov

    04/24/2019, 4:25 PM
    https://kotlinlang.slack.com/archives/C3PQML5NU/p1556051176164000
    s
    • 2
    • 3
  • r

    Rainer Schlonvoigt

    04/26/2019, 11:12 AM
    this doesn't seem to work, are there better alternatives? do i really need to make the field a string that just coincidentally is a byte array?
    -.php
    s
    • 2
    • 2
  • h

    hudsonb

    04/26/2019, 7:53 PM
    With the v0.11.0 release, can GeoJSON now be supported? It looks like the polymorphism stuff was merged in which I think enables the "Discriminator external" style that GeoJSON uses
    s
    • 2
    • 1
  • p

    pajatopmr

    04/29/2019, 6:48 PM
    IntelliJ does a nice job with @Serializable when generating code coverage info but Jacoco still has problems (I’m guessing with annotations that Kotlin needs to fix). In any case, is anyone aware of workarounds or solutions that get Jacoco to 100% on @Serializable code?
    g
    s
    • 3
    • 8
  • t

    thana

    04/30/2019, 2:14 PM
    im trying to serialzie a
    com.soywiz.klock.Year
    but doing so breakd code generation... Thats my serializer:
    class YearSerializer : KSerializer<Year> {
    
        override val descriptor: SerialDescriptor =
            StringDescriptor.withName("Klock-Year")
    
        override fun serialize(encoder: Encoder, obj: Year) {
            encoder.encodeInt(obj.year)
        }
    
        override fun deserialize(decoder: Decoder): Year {
            return Year(decoder.decodeInt())
        }
    }
    And thats how i use it (Month is an enum class i wrote):
    @Serializable
    data class LocalDate(val dayOfMonth: Int,
                         val month: Month, @Serializable(with = YearSerializer::class) val year: Year) {
        init {
            require(month.isDayOfMonthValid(dayOfMonth, year))
        }
    }
    s
    r
    • 3
    • 8
  • r

    ribesg

    05/03/2019, 2:00 PM
    I’ve got this in a test in
    commonTest
    which refers to a class in
    commonMain
    which is serializable:
    ClassNotFoundException: kotlinx.serialization.KSerializer
    What do?
    r
    • 2
    • 2
  • t

    themishkun

    05/06/2019, 9:23 AM
    I have a protobuf model of such:
    message Video {
       map<string,string> previews = 5;
       // ...
    }
    I want to deserialize it in the such data class
    @Serializable
    class Video(
       val thumbUrl: String
    )
    where thumbUrl === previews[“thumb”], any tips how to achieve that with kotlinx.serialization?
    • 1
    • 1
Powered by Linen
Title
t

themishkun

05/06/2019, 9:23 AM
I have a protobuf model of such:
message Video {
   map<string,string> previews = 5;
   // ...
}
I want to deserialize it in the such data class
@Serializable
class Video(
   val thumbUrl: String
)
where thumbUrl === previews[“thumb”], any tips how to achieve that with kotlinx.serialization?
Ok, here I made
previews
a private property and exposed
thumbUrl
as calculated one
View count: 8