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

    elizarov

    09/28/2017, 7:19 AM
    On the other hand, if
    MyData
    is
    @Serializable
    , then it opens the road to many formats at once. You can
    JSON.stringify(obj)
    or you can
    ProtoBuf.dump(obj)
    and to parcel it you’ll have to have some kind of a helper
    Parceller
    class and use it like
    Parceller.writeTo(parcel, obj)
    . You will not be able just to do
    parcel.writeValue(obj)
    , because a serializable object does not implement
    android.os.Parcelable
    ,
    g
    k
    • 3
    • 4
  • j

    jkbbwr

    09/28/2017, 1:41 PM
    Note that we are using proto2 semantics, where all fields are explicitly required or optional.
    Its a shame, would proto3 not be a better target?
    e
    s
    • 3
    • 4
  • k

    karelpeeters

    10/12/2017, 1:21 PM
    Continuing this discussion.
    b
    • 2
    • 2
  • e

    elizarov

    10/12/2017, 1:56 PM
    @karelpeeters Yes. It is possible write a “JS” format implementation that does exactly what you describe. We are considering to include in some future update.
    k
    b
    • 3
    • 11
  • k

    karelpeeters

    10/13/2017, 9:28 PM
    Hmm why would
    fun main(args: Array<String>) {
    println("Hello World!")
    println(JSON.plain.stringify(Foo("Hey")))
    }
    
    data class Foo(val foo: String)
    throw a
    ClassCastException: Illegal cast
    ? I'm using Kotlin-JS, so I don't have a stacktrace.
    s
    • 2
    • 1
  • n

    nulldev

    10/14/2017, 1:15 AM
    Does this library work with Android projects? I get this exception when attempting to serialize anything:
    kotlin.TypeCastException: null cannot be cast to non-null type kotlinx.serialization.KSerializer<T>
                                                                                       at kotlinx.serialization.SerializationKt.serializer(Serialization.kt:23)
    The code generation gradle plugin has been enabled using
    apply plugin: 'kotlinx-serialization'
    in
    app/build.gradle
    . The object to be serialized has a
    @kotlinx.serialization.Serializable
    annotation. Kotlin compiler version is
    1.1.51
    Am I missing something?
    s
    • 2
    • 4
  • j

    jkbbwr

    11/05/2017, 2:04 AM
    Seems like serialization doesnt work with 1.2?
    s
    • 2
    • 1
  • h

    hiperbou

    12/19/2017, 11:03 AM
    Hello, I'm trying to use kotlinx.serialization with a KotlinJs project without gradle or maven (don't ask :D). I've added the serialization runtime library manually and I can compile the examples. But, IntelliJ shows errors in the code as "unresolved reference kotlinx". I've tried to install the plugin as described in "Working in IntelliJ IDEA" section, but I get this warning "Plugin 'Kotlin-serialization' was already installed". I'm using the latest IntelliJ 2017.3.1. I supose I need to add the serialization plugin to the Kotlin compiler plugin. Can this be achieved?
    b
    s
    • 3
    • 44
  • l

    leandrodev

    12/19/2017, 6:16 PM
    Hello guys, I'm using kotlinx.serialization with a JVM project. I used the annotation
    SerialName
    to override properties names with custom names. But when attempting to serialize an enum object, I noticed that it doesn't work. Is there any other special annotation for enums? Another solution that I attempted was to write a custom serializer for my enum class. I've successfully implemented that, but when creating a
    JSON
    with
    unquoted = true
    , I noticed that it does not unquote only the value of my custom serializer. Is this something that implemented the wrong way?
    companion object: KSerializer<Status> {
            override fun save(output: KOutput, obj: Status) {
                output.writeStringValue(obj.description)
            }
    ...
    s
    • 2
    • 2
  • j

    jkbbwr

    12/28/2017, 12:41 AM
    Because kotlin has no concept of unions if I have two possible classes that can be deserialized how do I do that
    k
    • 2
    • 2
  • n

    nicolas.gonzalez

    01/27/2018, 7:44 PM
    I asked this question on stack overflow but maybe someone can help me here. Is about using serialization with generics to deserialize a Json response. I'm getting an error when the serialization plugin tries to generate the serializers for models with generics. See: https://stackoverflow.com/questions/48412340/cannot-parse-json-to-data-class-using-kotlinx-serialization
    s
    • 2
    • 2
  • e

    eric

    01/31/2018, 8:18 PM
    I'm trying to use the serialization library, but I'm getting the following when building with Gradle:
    Error:Kotlin: [Internal Error] java.lang.IllegalStateException: The provided plugin org.jetbrains.kotlinx.serialization.compiler.extensions.SerializationComponentRegistrar is not compatible with this version of compiler
    ... My IDE uses the latest stable Kotlin plugin (1.2.21-release-IJ2017.3-1). I have included the serialization plugin in my buildscript dependencies (`classpath 'org.jetbrains.kotlinx:kotlinx-gradle-serialization-plugin:0.4'). Is there something I haven't configured correctly for the plugin?
    s
    • 2
    • 9
  • g

    gaetan

    02/05/2018, 12:05 PM
    I’m trying to find a way of dealing with GeoJson (https://tools.ietf.org/html/rfc7946) in a multiplatform way. The specification indicates that the type of the property
    coordinates
    depends on the first property
    type
    . Expamples:
    {
      "type": "Point",
      "coordinates": [
        100,
        0
      ]
    }
    {
      "type": "LineString",
      "coordinates": [
        [
          100,
          0
        ],
        [
          101,
          1
        ]
      ]
    }
    s
    g
    • 3
    • 14
  • e

    ehubbard

    02/09/2018, 8:13 PM
    Trying to get serialization going — but am running into what seems to be a basic problem. Using gradle to build.. but when I try to serialize a real simple data class… I get kotlinx.serialization.SerializationException: Can’t locate default serializer for class class kotlin.Any
    s
    • 2
    • 11
  • r

    robstoll

    02/12/2018, 3:43 PM
    oh dear... this library does not seem to like me. I get
    class Xy is not externally serializable
    However, if I copy & paste the class into the place where I do the serialization it works. Can this library not deal with classes defined in other modules?
    s
    • 2
    • 2
  • y

    y2k_

    02/15/2018, 10:00 AM
    Guys, is there any way to serialize/deserialize
    sealed class
    to json (via kotlin-serialization of course)?
    s
    • 2
    • 1
  • j

    jacob

    02/21/2018, 9:24 AM
    hoping to be able to use https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/runtime_usage.md#obtaining-serializers but can't get intellij to recognise that the method exists
    s
    • 2
    • 3
  • o

    Olekss

    02/23/2018, 12:21 PM
    okay will reask here... how/if it's possible to serialize function(s)?
    o
    • 2
    • 1
  • t

    tschuchort

    02/25/2018, 7:11 PM
    where can I find documentation and sources for:
    org.jetbrains.kotlin.serialization.ProtoBuf
    and
    org.jetbrains.kotlin.serialization.jvm.JvmProtoBuf
    ?
    s
    • 2
    • 3
  • r

    rrva

    02/27/2018, 4:13 PM
    no, any tool is ok
    g
    • 2
    • 1
  • h

    hagabaka

    02/28/2018, 3:09 PM
    what I've done is have a
    Data
    class with nullable fields, and a
    Base
    class with a custom serializer which calls
    input.readValue() as Data
    in
    load
    and checks the null fields and constructs the right subtype
    s
    • 2
    • 2
  • j

    jacob

    03/01/2018, 1:46 AM
    or alternatively, so serialize a sub-object to
    Map<String, Any?>
    since I don't have a strict structure for it
    h
    • 2
    • 1
  • j

    jonathan

    03/02/2018, 5:42 AM
    Hi! I'm trying to use this to serialize messages to JSON -- I have a bunch of polymorphic definitions (see here: https://gist.github.com/jdkula/781c0edf83943df5e6dc9293f487029e) but I'm getting this error:
    java.lang.IllegalArgumentException: Can't locate polymorphic serializer definition
    (full stack trace: https://gist.github.com/jdkula/511b45a5de8224775418a39c23199d84) I'm compiling to Javascript from a common module. I'm using Kotlin 1.2.30.
    s
    h
    • 3
    • 5
  • t

    themishkun

    03/06/2018, 8:53 AM
    Hello guys, which library you can recommend for using with protobuf? Also, would be pleased if it can deal with data-classes and/or deserialize JSON as well
  • c

    chadmorrow

    03/06/2018, 10:24 PM
    So I was going to experiment with the kotlinx.serialization library today but installing the plugin for it breaks the kotlin plugin in intellij. The autogenerated error message the IDE gives just says null so I can’t submit the report from inside the IDE either. I saw a ticket that described this problem on youtrack but its closed. Anyone know of how to get this working?
    j
    n
    • 3
    • 3
  • j

    jonathan

    03/10/2018, 8:02 AM
    kotlinx.serialization is doing some weird name mangling when stringifying to JSON:
    JSON.stringify(UserRegistrationRequest("Jonathan"))
    Outputs:
    {
      "user_name": "Jonathan",
      "message_name_fojwga$_0": "user_request",
      "SENDER_SIDE_x0f2y$_0": {
        "name$": "CLIENT",
        "ordinal$": 1
      }
    }
    Where
    UserRegistrationRequest
    is:
    @Serializable
    class UserRegistrationRequest(val user_name: String) : SpyfallMessage {
        override val message_name = Companion.message_name // Overrides from interface SpyfallMessage
        override val SENDER_SIDE = Side.CLIENT  // Overrides from interface SpyfallMessage
        companion object {
            const val message_name = "user_request"
        }
    }
    s
    • 2
    • 11
  • n

    neworldlt

    03/15/2018, 7:16 PM
    I created a solution of this problem: https://github.com/Kotlin/kotlinx.serialization/pull/99
    s
    • 2
    • 6
  • r

    rrader

    03/16/2018, 3:00 PM
    Hi, is it possible to use kotlin serialization https://github.com/kotlin/kotlinx.serialization with Spring?
    s
    v
    • 3
    • 3
  • t

    Tristan Caron

    03/23/2018, 1:39 PM
    Hello, Do you have an example of how to use
    @SerialInfo
    ? I would like to use for deserialization. If a value is an empty string, I replace it by "NONE"
    s
    • 2
    • 1
  • s

    sandwwraith

    03/25/2018, 1:15 PM
    There is no AST for Json in
    kotlinx.serialization
    yet, but it’s planned
    👍 2
    n
    • 2
    • 2
Powered by Linen
Title
s

sandwwraith

03/25/2018, 1:15 PM
There is no AST for Json in
kotlinx.serialization
yet, but it’s planned
👍 2
n

Nail Gilaziev

03/25/2018, 2:14 PM
This is a good news. I am very forward to this functionality for multiplatform projects! when is it planned to do this? in the summer, in the autumn, in the winter of 2018 or in general to wait only next year?
s

sandwwraith

03/26/2018, 10:10 PM
I can’t tell about schedule yet, but this feature is a common request, so it definitely will be considered
View count: 8