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

    Marcin Wisniowski

    04/04/2021, 4:40 PM
    Hello, I have a class (external, can't edit source), that I made a custom serializer for. It works fine like this:
    @Serializable(with = MySerializer::class) val item: MyClass
    But now I need to serialize a list of these items:
    val items: List<MyClass>
    How can I make it work? I cannot use the same annotation, since now it's a
    List
    .
    r
    • 2
    • 2
  • d

    diesieben07

    04/06/2021, 3:01 PM
    Another question: I need to deserialize an object with a property that can either be a boolean or a nested object. How can I achieve this with kotlinx.serialization?
    j
    c
    a
    • 4
    • 40
  • m

    Marcin Bak

    04/06/2021, 9:16 PM
    In a new IntelliJ kotlin multiplatform project after adding
    kotlin("plugin.serialization")
    and serialization dependency in common module I don't get generated serializers and get a warning on
    @Serializable
    kotlinx.serialization compiler plugin is not applied to the module, so this annotation would not be processed. Make sure that you've setup your buildscript correctly and re-import project.
    The main build.gradle.kts contains proper buildscript dependencies
    classpath(kotlin("gradle-plugin", version = "1.4.31"))
    classpath(kotlin("plugin.serialization", version = "1.4.31"))
    Nothing seems to help. I've removed all unnecessary code, reimported project, invalidated caches but to no avail. Any ideas?
    a
    a
    +4
    • 7
    • 14
  • y

    Yardenavirav

    04/08/2021, 11:04 PM
    Is there an "idiomatic" way to assign the default value of a property when a
    JsonDecodingException
    is produced BECAUSE of that property? I can workaround it by using a custom serializer for that property but it's quite an overhead. e.g - for this data class
    data class AA(val a: Int = 0)
    and this json
    {"a":"N/A"}
    I will get this output
    AA(a = 0)
    despite it failed to decode it.
    h
    • 2
    • 3
  • p

    Prayansh Srivastava

    04/13/2021, 10:00 PM
    Hi! :android-wave: This might be a dumb question, but is it possible to annotate and auto-generate serializers for a POJO class in a java file? I am trying something like this
    // MainActivity.java
    
    public class MainActivity extends Activity {
    
        @Serializable
        static class Props {
            // my POJO
            int count;
            String name;
        }
    
        @Override
        public void onCreate() {
            super.onCreate();
            Props.serializer() // No such method available
        }
    }
    I am not sure if i am misusing / misunderstanding the API here, so feel free to correct 🙂 Thx!
    n
    • 2
    • 3
  • t

    Tomas Kormanak

    04/15/2021, 1:20 PM
    Hi, I am trying to serialize data class and getting empty object as result, I can't find out what is wrong
    @Serializable
    data class Params(val deviceId: String = "someId")
    
    val params = Params()
    
    val result  = Json.encodeToString(Params.serializer(), params)
    console.log("params", params)
    console.log("result ",  result)
    I get this result:
    p
    p
    • 3
    • 4
  • j

    Justin Tullgren

    04/15/2021, 9:04 PM
    Hi, I am getting an error and I can't figure out how the default polymorphic serializer is messing it up:
    kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 26: Expected '[, kind: SEALED'
    Any help is appreciated.
    r
    j
    • 3
    • 10
  • r

    rocketraman

    04/21/2021, 6:55 PM
    Is the JSON serializer deterministic? i.e. if two input data classes are equal, will it always produce the same output, regardless of where and when? I think we can assume the same version of kotlinx-serialization is always used.
    d
    e
    • 3
    • 4
  • t

    thanksforallthefish

    04/23/2021, 2:25 PM
    hello 🙂. is there something similar to
    @JsonAnyGetter
    from jackson in kotlinx serialization? or, assuming I have a json like
    {
      field: value,
      second: value,
      another: value
    }
    how can I map into something a class like
    @Serializable
    class MyClass(val field: String, val additional: Map<String, String>)
    ? bonus question, coming from jackson, I spent most of day trying to figure out how to handle
    val additional: Map<String, Any>
    , but that is not really possible with kotlin serialization right?
    e
    • 2
    • 3
  • y

    Yaniv Sosnovsky

    04/24/2021, 3:16 PM
    Hi can anyone help we with kotlin deserialization? I’m using retrofit with kotlinx serialization and I have a case where I can get 2 types of responses from the server: the first case returns a list of results with “drinks” key,
    {"drinks":[{"strDrink":"Jelly Bean","strDrinkThumb":"https:\/\/<http://www.thecocktaildb.com|www.thecocktaildb.com>\/images\/media\/drink\/bglc6y1504388797.jpg","idDrink":"13775"},{"strDrink":"Turf Cocktail","strDrinkThumb":"https:\/\/<http://www.thecocktaildb.com|www.thecocktaildb.com>\/images\/media\/drink\/utypqq1441554367.jpg","idDrink":"12418"}]}
    but sometimes the server returns the following:
    "{"drinks":"None Found"}"
    Before using kotlinx I had a custom type convertor with Gson, and that worked fine, but I’m struggling with kotlin. I tried to create a KSerializer to try to parse the result, and return an object with an empty list if an exception is thrown, but I keep getting this exception:
    java.lang.IllegalStateException: Reader has not consumed the whole input: JsonReader(source='{"drinks":"None Found"}', currentPosition=22, tokenClass=1, tokenPosition=10, offset=11)
    Any ideas how to solve this? I can always return a string instead of a data class, but this is ugly AF
    e
    • 2
    • 4
  • s

    spierce7

    04/26/2021, 7:21 AM
    I see that protobuf for kotlinx.serialization is still considered “experimental”. In what regard is it experimental? Are certain features in JSON not supported in protobuf?
    👀 1
    r
    b
    • 3
    • 9
  • d

    Denys

    04/26/2021, 1:22 PM
    Hi all! I’m having an annoying problem with Proguard for Kotlinx Serialization. I have a class like this
    @Serializable
    data class PagedResult<T, P : PagedResult.Pagination>(val items: List<T>, val pagination: P)
    Everything works fine until the moment when I enable Proguard. An error like this occurs: java.lang.IllegalArgumentException: Unable to create converter for f.a.b.d.i.g.a<> (). f.a.b.d.i.g.a is just a class PagedResult (I see it in mapping.txt) The rules for Proguard are taken from the official kotlinx.serialization repository. Can someone tell me what the problem is?
    e
    • 2
    • 3
  • k

    Karlo Lozovina

    04/28/2021, 10:17 AM
    Given a class like
    data class Foo(val foo: String)
    is there an easy way to serialize it into just a string, not an object like
    {"foo": "SomeString"}
    ? without writing a custom serializer...
    j
    • 2
    • 7
  • k

    Karlo Lozovina

    04/28/2021, 6:11 PM
    Huh, switching kotlinx.serialization to 1.2.0 (unreleased?) seems to fix it...
    :thread-please: 1
    j
    • 2
    • 9
  • a

    andrewreitz

    04/28/2021, 7:32 PM
    Hi, I’m testing my model w/ json serialization. I’m serializing my models to json and then deserializing them back into my model object. Nodejs and native mac are working fine, but the test on java is throwing this cryptic error
    java.lang.ClassCastException: class [[Ljava.lang.Object; cannot be cast to class [[Ljava.lang.Float; ([[Ljava.lang.Object; and [[Ljava.lang.Float; are in module java.base of loader 'bootstrap')
    	at raytracer.math.Matrix$$serializer.deserialize(Matrix.kt:9)
    	at raytracer.math.Matrix$$serializer.deserialize(Matrix.kt:9)
    	at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:63)
    	at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:32)
    	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43)
    	at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70)
    Any ideas of where to look and how to fix that?
    r
    • 2
    • 3
  • n

    Norbi

    04/29/2021, 9:09 PM
    I have upgraded to 1.5.0-RC and I get this error no matter what I try :( Stacktrace:
    'void kotlinx.serialization.modules.SerialModuleImpl.<init>(java.util.Map, java.util.Map, java.util.Map, java.util.Map)'
    java.lang.NoSuchMethodError: 'void kotlinx.serialization.modules.SerialModuleImpl.<init>(java.util.Map, java.util.Map, java.util.Map, java.util.Map)'
    at kotlinx.serialization.modules.SerializersModuleKt.<clinit>(SerializersModule.kt:74)
    at kotlinx.serialization.json.Json$Default.<init>(Json.kt:65)
    at kotlinx.serialization.json.Json$Default.<init>(Json.kt)
    at kotlinx.serialization.json.Json.<clinit>(Json.kt)
    at kotlinx.serialization.json.JsonKt.Json$default(Json.kt:130)
    - Kotlin version: 1.5.0
    - kotlinx-serialization version: 1.2.0
    - Kotlin platforms: multiplatform (JVM + JS)
    - Gradle version: 6.8.3
    - IDE version: 2021.1.1 RC
    - Other relevant context: Java 15
    Have you seen anything similar? Thanks.
    k
    • 2
    • 4
  • r

    Ryan Simon

    04/30/2021, 4:09 PM
    hey all, I'm having some trouble with dynamic deserialization on kotlin native. i've included relevant code in the thread. would appreciate some help on this one, thank you in advance!
    b
    • 2
    • 11
  • y

    Yuri Drigin

    05/01/2021, 9:00 AM
    Hi folks! I have an error in generic class after upgrade serialization to 1.2.0. Can you suggest why?
    Untitled
    t
    • 2
    • 3
  • a

    Adam S

    05/01/2021, 6:56 PM
    hi, how can I make data class with empty arrays encode to empty json arrays?
    val jsonMapper = Json {
            prettyPrint = true
            encodeDefaults = true
            coerceInputValues = true
          }
          val inputPet = Pet(
            name = petName,
            tags = emptyList(),
            photoUrls = emptyList(),
            status = petStatus
          )
          val inputPetJson = jsonMapper.encodeToString(inputPet)
    Actual :{"name":"blaaaah","status":"available"}
    Expected:{"name":"blaaaah","photoUrls":[],"tags":[],"status":"available"}
    I’ve tried various combinations of encodeDefaults and coerceInputValues. The problem is that
    Pet
    has other fields that default to null. I don’t want to include those.
    d
    • 2
    • 3
  • m

    Mikhail Buzuverov

    05/03/2021, 4:21 AM
    Hello. I bumped into issue: serialization works well in JVM, but fails in JS with exception (
    1.2.0
    library version):
    TypeError: tmp$.serializer is not a function
    	at <global>.compiledSerializerImpl(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_490920/commons.js:72080)
    	at <global>.serializerOrNull(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_490920/commons.js:67234)
    	at <global>.reflectiveOrContextual(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_490920/commons.js:67226)
    	at <global>.builtinSerializer(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_490920/commons.js:67220)
    	at <global>.serializerByKTypeImpl(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_490920/commons.js:67159)
    	at <global>.serializer(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_490920/commons.js:67129)
    	at data.OperationResultSerializationTest.operationSuccessSerializationTest(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_490920/commons.js:77540)
    	at <global>.<unknown>(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_490920/commons.js:77588)
    	at Context.<anonymous>(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_490920/commons.js:57)
    Or (with
    1.1.0
    library version):
    SerializationException: Serializer for class 'OperationResult' is not found.
    Mark the class as @Serializable or provide the serializer explicitly.
    On Kotlin/JS explicitly declared serializer should be used for interfaces and enums without @Serializable annotation
    	at Object.captureStack(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_73575/commons.js:40068)
    	at SerializationException.constructor(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_73575/commons.js:40401)
    	at SerializationException.constructor(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_73575/commons.js:40427)
    	at SerializationException.constructor(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_73575/commons.js:40447)
    	at IllegalArgumentException.init(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_73575/commons.js:40458)
    	at SerializationException.init(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_73575/commons.js:67048)
    	at <global>.platformSpecificSerializerNotRegistered(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_73575/commons.js:72030)
    	at <global>.serializer(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_73575/commons.js:67125)
    	at data.OperationResultSerializationTest.operationSuccessSerializationTest(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_73575/commons.js:77226)
    	at <global>.<unknown>(C:/Users/Akela/AppData/Local/Temp/_karma_webpack_73575/commons.js:77274)
    I described the issue: https://github.com/Kotlin/kotlinx.serialization/issues/1448 Could you help me? Is there a workaround?
    😕 1
    t
    t
    • 3
    • 6
  • r

    robertoestivill

    05/05/2021, 11:32 AM
    [Dynamic or “Per class” classDiscriminator ?]
    d
    j
    • 3
    • 5
  • r

    ribesg

    05/07/2021, 1:22 PM
    Updated a big KMP multi-module project to Kotlin 1.5.0 and kotlinx.serialization 1.2.0 and I get this error while building a very small module with just 3 files. Is there a way to know what causes this?
    kotlinx.serialization compiler error.txt
    t
    • 2
    • 2
  • d

    Dominaezzz

    05/09/2021, 9:52 PM
    How are custom formats types supposed to be handled/represented? SerialInfo annotation? inline class? Custom serializer for annotation?
    b
    • 2
    • 2
  • r

    Robert Jaros

    05/10/2021, 9:54 PM
    This bug https://github.com/Kotlin/kotlinx.serialization/issues/1464 makes 1.2.0 release completely unusable in realworld apps. Can we expect a quick hotfix release?
    s
    • 2
    • 2
  • h

    Helio

    05/11/2021, 7:59 AM
    Hello everyone, 👋🏽 I’ve had a look at Kotlinx.Serialization documentation, and also looked for examples, but I couldn’t find the best practice for the case I’m going to describe. I wonder if anyone would be able to provide any insight. Also, I’m not an advanced user of the library. I have an server that return a JSON Payload containing a single Status property:
    {
      "status": "OneOf<Pending|Queued|InProgress|Finished|NotBuilt>"
    }
    If I want to serialise it to Enum, I would have:
    @Serializable
    enum class Status {
        @SerialName("Pending") PENDING,
        @SerialName("Queued") QUEUED,
        @SerialName("InProgress") IN_PROGRESS,
        @SerialName("Finished") FINISHED,
        @SerialName("NotBuilt") NOT_BUILT,
    }
    
    @Serializable
    data class ServerResponseModel(val status: Status)
    However, when I get a response from the server, let’s say
    InProgress
    all I need to do is build a new Model and return the status as being
    IN_PROGRESS
    . What would be the best way to achieve that? Do I need to write a custom serialisation in this case? Also, does it makes sense to create an
    Enum class
    for
    ServerResponseModel
    ? Thanks for your assistance.
    p
    • 2
    • 8
  • t

    tylerwilson

    05/11/2021, 12:47 PM
    Trying serialization 1.2.0 in existing MPP lib, using Kotlin compiler 1.4.32. I get the following on iOS (when parsing a JSON network response):
    kotlin.native.concurrent.InvalidMutabilityException: mutation attempt of frozen kotlin.collections.HashMap@955628
    This works fine with serialization 1.1.0. Should the new serialization work with Kotlin 1.4.32? Do we need an updated coroutines lib?
    t
    • 2
    • 5
  • m

    Michael Friend

    05/12/2021, 6:51 PM
    When using polymorphic serialization is there any way to 1. have the class discriminator available as a property on the base class 2. default to a particular subclass? My usecase has the
    type
    property on the json object somewhat overloaded where for one value i want to deserialize it into class A, but any other value is of type B and I need access to the
    type
    value. Adding
    type
    as a property gives an error
    because it has property name that conflicts with JSON class discriminator 'type'. You can either change class discriminator in JsonConfiguration, rename property with @SerialName annotation or fall back to array polymorphism
    I couldnt find any reference too array polymorphism anywhere
    d
    • 2
    • 2
  • m

    Michael

    05/13/2021, 9:43 PM
    Found completely random bug
    @Serializable
    data class Example(val content: String)
    
    suspend fun main(args: Array<String>) {
        val content2 = "a".repeat(126) + "\n"
        Json.encodeToString(content2)
    }
    This fails if as long as the number is >= 126
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 129 out of bounds for length 129
    	at kotlinx.serialization.json.internal.JsonStringBuilder.appendStringSlowPath(JsonStringBuilder.kt:102)
    	at kotlinx.serialization.json.internal.JsonStringBuilder.appendQuoted(JsonStringBuilder.kt:61)
    	at kotlinx.serialization.json.internal.Composer.printQuoted(Composers.kt:42)
    	at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeString(StreamingJsonEncoder.kt:203)
    	at kotlinx.serialization.internal.StringSerializer.serialize(Primitives.kt:139)
    	at kotlinx.serialization.internal.StringSerializer.serialize(Primitives.kt:136)
    	at kotlinx.serialization.json.internal.StreamingJsonEncoder.encodeSerializableValue(StreamingJsonEncoder.kt:211)
    	at kotlinx.serialization.json.Json.encodeToString(Json.kt:80)
    r
    • 2
    • 3
  • p

    Peter Vegh

    05/15/2021, 12:29 PM
    Is there a way to user kotlinx serialization in a foo.main.kts?
    m
    d
    b
    • 4
    • 11
  • s

    spierce7

    05/16/2021, 4:38 PM
    @sandwwraith Working with Firebase’s Firestore isn’t very convenient in Kotlin. How feasible is it to leverage kotlinx.serialization to “serialize” between kotlin classes and object formats that Firestore requires in Kotlin multiplatform? i.e. • In JVM I’d need to take a Kotlin data class and convert it into
    Map<String, Any>
    and
    Date
    representations into Firestore’s
    Timestamp
    . • In JS I’d need to output js objects (Not kotlin Map’s or anything) Assuming this is possible: 1. Would I be able to stay away from Compiler plugins and stick only to the runtime? 2. Would configuring an object to change to Firestore types present any problems to that same object being serialized to json?
    s
    • 2
    • 8
Powered by Linen
Title
s

spierce7

05/16/2021, 4:38 PM
@sandwwraith Working with Firebase’s Firestore isn’t very convenient in Kotlin. How feasible is it to leverage kotlinx.serialization to “serialize” between kotlin classes and object formats that Firestore requires in Kotlin multiplatform? i.e. • In JVM I’d need to take a Kotlin data class and convert it into
Map<String, Any>
and
Date
representations into Firestore’s
Timestamp
. • In JS I’d need to output js objects (Not kotlin Map’s or anything) Assuming this is possible: 1. Would I be able to stay away from Compiler plugins and stick only to the runtime? 2. Would configuring an object to change to Firestore types present any problems to that same object being serialized to json?
s

sandwwraith

05/17/2021, 9:22 AM
1. Yes, that's what the custom formats mechanism for. 2. I don't get what 'configuring an object to change to Firestore types' mean. Changing the types in the object declaration? Then the answer depends on how that types are serialized to json.
s

spierce7

05/17/2021, 3:03 PM
@sandwwraith 1. Can you give me more information and point me in the right direction for the custom formats mechanism? 2. Nevermind, I’m pretty confident this won’t be an issue.
This is what you mean? https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/formats.md#custom-formats-experimental
s

sandwwraith

05/17/2021, 3:07 PM
Yes, exactly
s

spierce7

05/17/2021, 3:08 PM
Man - you have great documentation for this! This is exactly what I was looking for. I’m pretty excited for this!
😉 1
@sandwwraith Do I have the ability to have information of custom annotations in the encoder?
s

sandwwraith

05/24/2021, 10:51 AM
Yes, they are stored in the corresponding
SerialDescriptor.annotations
(for class)
SD.getElementAnnotations
(for properties)
Annotation should be marked as
@SerialInfo
itself
View count: 11