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

    rrva

    06/04/2020, 7:25 PM
    0.20.0 breaks when upgrading kotlin to 1.4-M2:
    kotlinx.serialization.CompositeDecoder kotlinx.serialization.Decoder.beginStructure(kotlinx.serialization.SerialDescriptor)’
    java.lang.NoSuchMethodError: 'kotlinx.serialization.CompositeDecoder kotlinx.serialization.Decoder.beginStructure(kotlinx.serialization.SerialDescriptor)
    r
    • 2
    • 4
  • m

    Marcin Wisniowski

    06/04/2020, 9:20 PM
    Hello, I am trying to serialize a data class containing a
    java.time.Duration
    , but it doesn't work (
    java.time.Instant
    works fine), do I need to write a custom serializer? How can I serialize a Duration?
    • 1
    • 1
  • e

    edenman

    06/05/2020, 1:56 AM
    i am trying to consume a protobuf API over json and it uses
    oneof
    extensively. i originally built my data objects as just normal data classes with nullable fields representing the various oneof field options, but I’d really like to represent this with a sealed class. I started writing a custom decoder but I can’t figure out how to essentially “peek” and see which field is present so I know which serializer to use. anybody done this successfully?
    • 1
    • 6
  • s

    Sam Garfinkel

    06/08/2020, 8:16 PM
    Is there anyway to override the default polymorphic serialization for sealed classes? I’d like to redefine how subclasses are disambiguated.
    e
    • 2
    • 7
  • j

    Justin

    06/09/2020, 6:36 PM
    What is the suggested approach for declaring a type that is basically
    Any
    but constrained to
    String | Boolean | Int | Array | Map
    , and then make that type serializable? Because there are no true union types in Kotlin, what I tried to do is this:
    @Serializable
    sealed class Value<out T>(val value: T) {
        class STRING(value: String): Value<String>(value)
        class BOOLEAN(value: Boolean): Value<Boolean>(value)
        class NUMBER(value: Number): Value<Number>(value)
        class ARRAY<V>(value: List<V>): Value<List<V>>(value)
        class DICTIONARY(value: Map<String, Any?>): Value<Map<String, Any?>>(value)
        object NULL: Value<Nothing?>(null)
    }
    Then, I have a number of data classes/interfaces that need to use this type, for example:
    interface StoredValue {
        val type: String
        val value: JsonElement // This would become of type Value
    }
    @Serializable
    data class NetworkRequest(
        val type: String,
        val data: JsonElement // This would become of type Value
    )
    But if I try to use
    Value
    in place of
    JsonElement
    , then I need to attach the generic type parameter to those classes/interfaces, and then I'm not sure how to deal with serialization on them.
    b
    • 2
    • 3
  • n

    Nikky

    06/11/2020, 2:48 PM
    is there anything like a alias for SerialModule ? or any other way to move / refactor sealed classes and have it parse old json that has values for
    type
    ?
    d
    • 2
    • 12
  • c

    Chetan Sachdeva

    06/13/2020, 7:35 AM
    I want to serialize
    SomeType
    to a
    String
    and I’m using a custom
    KSerializer<SomeType>
    . I tried:
    Json.stringify(SomeTypeSerializer, SomeType("some"))
    But in the output I get
    ""some""
    . Is there a way to get
    "some"
    (without extra quotes)?
    • 1
    • 1
  • j

    janvladimirmostert

    06/13/2020, 9:50 AM
    does Kotlin Serialization support delegated properties or will i need to implement a custom serializer for that?
    @Serializable
    class Test {
    
        var firstName: String by Delegates.observable(
            initialValue = "Someone",
            onChange = { _, _, _ ->
                println("firstName changed")
            }
        )
    
    }
    val json = Json(JsonConfiguration.Stable)
        val test = Test()
        test.firstName = "Person"
        val jstring = json.toJson(Test.serializer(), test)
        println(jstring.toString())
    ouputs:
    {}
    • 1
    • 2
  • s

    Sam

    06/15/2020, 4:20 PM
    Is there a way to force a double to serialize to an int when it is a whole number? Failing that, is there a way to supply a custom serializer for only one class in a sealed class?
    • 1
    • 1
  • s

    Slackbot

    06/16/2020, 5:40 PM
    This message was deleted.
    v
    • 2
    • 1
  • r

    Rodrigo Silva

    06/16/2020, 9:42 PM
    I'm trying to use kotlinx but I'm getting this error:
    n
    • 2
    • 4
  • c

    camdenorrb

    06/18/2020, 6:36 AM
    I'm trying to deserialize 2 JsonObjects but I appear to be having issues, any help is appreciated:
    • 1
    • 4
  • c

    christophsturm

    06/19/2020, 12:01 PM
    is there no
    org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:0.20.0-1.4-M2
    package?
    r
    • 2
    • 2
  • p

    Paul Woitaschek

    06/22/2020, 2:12 PM
    What's the status on null values in protobuf right now? If I get it correctly protobuf 3 is capable of null values?
    g
    • 2
    • 15
  • e

    edenman

    06/23/2020, 10:35 PM
    anybody else seen
    class file for kotlinx.serialization.KSerializer not found
    kapt errors before?
    • 1
    • 3
  • j

    Jake

    06/24/2020, 4:10 PM
    Say I have json that looks like this 
    {
      "versions": {
          "android": {
              "recommended": "2020.06.01",
              "minimum": "2020.05.22"
          },
    
          "ios": {
              "recommended": "2020.06.01",
              "minimum": "2020.05.22"
          }
      }
    }
    And I want my model to look like this:
    @Serializable
    data class AppVersions(val recommended: String, val minimum: String)
    Does anyone know how to use the Serializer to ignore a layer and look for
    versions/android
    ? Is it as simple as assigning the Serial Name like that?
    • 1
    • 1
  • p

    Paul Woitaschek

    07/01/2020, 2:02 PM
    In general protubf seems really buggy. I.e. this code:
    ProtoBuf.dump(Int.serializer().set, setOf())
    Also just throws an exception:
    Exception in thread "main" java.util.NoSuchElementException: List is empty.
    	at kotlin.collections.CollectionsKt___CollectionsKt.last(_Collections.kt:372)
    	at kotlinx.serialization.internal.TaggedEncoder.getCurrentTag(Tagged.kt:129)
    	at kotlinx.serialization.protobuf.ProtoBuf$ProtobufWriter.beginStructure(ProtoBuf.kt:112)
    	at kotlinx.serialization.Encoder$DefaultImpls.beginCollection(Encoding.kt:244)
    	at kotlinx.serialization.internal.TaggedEncoder.beginCollection(Tagged.kt:22)
    	at kotlinx.serialization.internal.ListLikeSerializer.serialize(CollectionSerializers.kt:73)
    	at kotlinx.serialization.protobuf.ProtoBuf$ProtobufWriter.encodeSerializableValue(ProtoBuf.kt:148)
    	at kotlinx.serialization.EncodingKt.encode(Encoding.kt:402)
    	at kotlinx.serialization.protobuf.ProtoBuf.dump(ProtoBuf.kt:541)
    	at kotlinx.serialization.protobuf.ProtoBuf$Default.dump(ProtoBuf.kt)
    e
    • 2
    • 1
  • e

    ephemient

    07/01/2020, 8:08 PM
    can kotlinx.serialization be convinced to allow for some non-exact class matches when polymorphic? I'd like to use it on various data structures containing
    CharSequence
    . regardless of the exact type, I want to handle them all the same way - serialize their
    .toString()
    , and a subset of their spans if
    Spannable
    (Android interface), ignoring everything else. but it seems like polymorphic(CharSequence::class) is forcing me to write a separate serializer for every possible concrete class
    • 1
    • 1
  • a

    andylamax

    07/03/2020, 10:18 AM
    does kotlinx serialization in jvm rely on reflection?
    k
    • 2
    • 3
  • a

    andylamax

    07/03/2020, 11:11 AM
    How do I make this polymorphically serializable?
    @Serializable
    sealed class Result<T> {
        @Serializable
        class Success<T>(val data: T) : Result<T>()
    
        @Serializable
        class Failure<T>(val msg: String) : Result<T>()
    }
    So that If I have a class
    @Serializable
    data class Person(val name:String)
    I can call
    Json.stringify(Result.Serializer(Person.serializer()),Result.Success(Person("Andy)))
    I have little knowledge in Polymorphic Serialization
    k
    j
    • 3
    • 8
  • b

    bsimmons

    07/03/2020, 2:57 PM
    Hey all. So I got a cryptic
    UnsupportedOperationException: IrValueParamterImple...
    error and spent an hour trying to find out why. Had to move some private var initializations into the init{} function to get things working. Is the dev team is interested in perhaps making this error a bit less cryptic? If so, I could open a Github issue.
    a
    • 2
    • 4
  • b

    bjonnh

    07/07/2020, 11:34 PM
    I'm having issues to resolve the serialization runtime: https://pastebin.com/raw/uEj4DrHx
    a
    • 2
    • 3
  • c

    christophsturm

    07/09/2020, 9:25 AM
    does
    @serializable
    make the class implement an interface? i would like to have a generic method accept only serializable classes, something like
    <T : Serializable>
    m
    e
    • 3
    • 11
  • e

    edenman

    07/09/2020, 11:11 PM
    trying to use the new 1.4-M3 but getting this error
    Plugin [id: 'org.jetbrains.kotlin.plugin.serialization', version: '1.4-M3'] was not found in any of the following sources:
    …i added
    maven ("<https://dl.bintray.com/kotlin/kotlin-eap>")
    to my
    repositories
    but still no luck, anybody know how to fix?
    c
    • 2
    • 7
  • a

    Aaron Todd

    07/13/2020, 1:27 PM
    is JsonElement appropriate for comparing arbitrary JSON strings for equality? It seems to work fine but I haven't done any kind of exhaustive testing, wondering if anyone else has used it for that
    b
    • 2
    • 2
  • p

    pmiklos

    07/17/2020, 5:21 AM
    Hi guys, would it be possible to bring the
    classDiscriminator
    from context level to base class level? For example
    @Polymorphic(discriminator="command")
    or as part of the SerialModule:
    polymorphic("command", Message::class) { ... }
    or similar? It would add a great flexibility and it doesn't seem very difficult to add to the current design.
    t
    • 2
    • 1
  • i

    Ian

    07/19/2020, 7:21 PM
    Can anyone clarify whether `ByteArray`s are currently serialized efficiently to CBOR format?
    d
    p
    t
    • 4
    • 5
  • b

    Brandon Saunders

    07/24/2020, 7:45 AM
    Hi here, I have a question on custom deserializers. If I want to use the approach 2 from here, https://medium.com/transferwise-engineering/how-to-master-polymorphism-and-custom-serializers-in-kotlinx-serialization-7190da0f42aa to define a custom serializer on a data object, is there a way to still use the default deserializer for the class within the custom one? For the use case, we want to be able to use the default deserializer exactly as is and AFTER deserializing then set the json blob as a field on the class. (We need to do this to support phasing out existing deserializers while we're replacing the old classes with our new classes from a library)
    n
    • 2
    • 3
  • s

    SrSouza

    07/25/2020, 9:05 PM
    Hi folks, I'm creating a new type of encoding here for my project and I want to be able to get Annotations in Generic Types of a List or Map in the SerialDescriptor, is possible? I know that this is possible
    val messages: List<@Serializable(with = ChangeColor::class) String>
    and I'm trying a lot here and I could not find a way. I want to be able to do something like this:
    val messages: List<@ChangeColor String>
    s
    • 2
    • 1
  • r

    Robert Jaros

    07/27/2020, 2:37 PM
    kotlin-1.4-rc
    requires serialization
    1.0-M1-1.4.0-rc
    . Is there any changelog for 1.0 release?
    b
    • 2
    • 3
Powered by Linen
Title
r

Robert Jaros

07/27/2020, 2:37 PM
kotlin-1.4-rc
requires serialization
1.0-M1-1.4.0-rc
. Is there any changelog for 1.0 release?
b

Brett Best

08/05/2020, 5:54 AM
Hey Robert, I see it looks like you’ve gotten kotlin serializiation to work with with kotlin 1.4. I’m having trouble integrating this version into my gradle files, I don’t suppose you could help me out?
@Robert Jaros I’ve added
id "org.jetbrains.kotlin.plugin.serialization" version "1.4.0-rc"
to my plugins and
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // or "kotlin-stdlib-jdk8"
    implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:1.0-M1-1.4.0-rc" // JVM dependency
To my dependencies
r

Robert Jaros

08/05/2020, 11:12 AM
I didn't have any problem with the version itself. Just changed the number and it worked for me (but my projects are mostly JS or MPP, so the layout of dependencies is probably different).
View count: 3