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

    ivan.savytskyi

    09/11/2020, 8:23 PM
    hey folks, after migrating to 1.0.0 version from 0.20.0, we noticed that API around
    JsonLiteral
    has changed. It's now
    internal
    and
    body
    is no longer field on class. We have some business logic that was relying on getting access to raw value
    body
    to understand what type is that value. Now looks like there is no way to say what type was the value when
    JsonPrimitive
    was created. The only hint
    isString
    flag that doesn't really helps. What was the main rationale of hiding
    JsonLiteral
    and
    body
    ? Is there any plans to introduce more subclasses of
    JsonPrimitive
    like
    JsonNumberPrimitive
    ,
    JsonBooleanPrimitive
    to better represent the primitive value type?
    v
    • 2
    • 7
  • j

    Jan Skrasek

    09/14/2020, 1:08 PM
    How serialization actually works? Is it a compiler plugin? Is it faster than kapt? Will it be faster than KSP in future?
    j
    • 2
    • 5
  • m

    melatonina

    09/16/2020, 11:03 AM
    Hello. Where can I find the documentation for the version 0.14.0 of the API for writing custom serializers? I'm interested in using
    encoder.beginCollection()
    , in particular. The signature is
    fun beginCollection(desc: SerialDescriptor, collectionSize: Int, vararg typeParams: KSerializer<*>)
    . What is
    desc
    the descriptor of? What are the
    typeParams
    ? I can't upgrade to 0.20.0 because I can't use the compiler beyond 1.3.61 at the moment (Arrow meta won't work).
    e
    • 2
    • 3
  • z

    zeugederunity

    09/16/2020, 5:27 PM
    Hello everyone, after updating to Kotlin 1.4.10 with Serialization 1.0.0-RC I realized, that the 
    SerialName
     annotation was set to 
    retention(BINARY)
    Is there any way in Kotlin 1.4.x with Serialization 1.0.0-RC to retrieve the 
    SerialName
     of an annotated property? Because reflection is now not possible anymore.
    v
    • 2
    • 4
  • r

    Ryan Batchelder

    09/16/2020, 5:34 PM
    Were there major changes to deserializing dynamic objects from JS in Serialization 1.0.0-RC? I know the API has changed to merge the
    DynamicObjectParser
    into
    Json
    , but when trying to use
    .decodeFromDynamic()
    I'm getting
    IllegalStateException: This serializer can be used only with Json format.Expected Decoder to be JsonDecoder, got class DynamicInput
    The serializer in this case is a small data class annotated with
    @Serializable
    , and I've also tried using
    JsonObject.serializer()
    with the same results. How can I handle serializing a dynamic from a JS library into a Kotlin object in this case?
    v
    • 2
    • 9
  • t

    TwoClocks

    09/16/2020, 8:56 PM
    Intermittently can't get CBOR decoding to compile. I get this error a lot
    Type mismatch: inferred type is ByteArray but DeserializationStrategy<TypeVariable(T)> was expected
    v
    t
    • 3
    • 28
  • t

    TwoClocks

    09/16/2020, 10:19 PM
    What is wrong w/ this CBOR code (1.0.0-RC, kotlin ver : 1.4.10) Throws the exception on the decode:
    kotlinx.serialization.cbor.internal.CborDecodingException: Expected start of array, but found BF
    @Serializable
    sealed class BaseClass()
    
    @Serializable
    data class TypeOne(val name:String) : BaseClass()
    
    @Serializable
    data class TypeTwo(val num:Int) : BaseClass()
    
    
    @ExperimentalSerializationApi
    fun main(args: Array<String>) {
        
        val bb = Cbor.encodeToByteArray(TypeOne("my name is mud"))
    
        val msg = Cbor.decodeFromByteArray<BaseClass>( bb )
        
        println(msg)
    
    }
    v
    v
    • 3
    • 19
  • t

    TwoClocks

    09/17/2020, 2:18 AM
    yeah. encoding a list of more than one
    BaseClass()
    includes the type info. But encoding just one (or a list of one) of the subtypes will not generate the
    "type":
    field in the result. How do you force the type info to be present?
    • 1
    • 1
  • g

    Greg Steckman

    09/20/2020, 5:10 PM
    Hello, I am trying to serialize/deserialize a class with an inner class. Upon deserialization, the inner class does not have a reference to its enclosing outer class, and will throw a null pointer exception when referencing a property of the outer class. Below is an example. Class definition:
    @Serializable
    class OuterTestClass(val x: Int){
        val inner = InnerTestClass(5)
    
        @Serializable
        inner class InnerTestClass(val y: Int){
            fun compute(): Int{
                return x*y
            }
        }
    }
    Example test, where a null pointer exception is thrown at the call to o2.inner.compute():
    @Test
    fun testInnerClassesAreSerializable(){
        val o1 = OuterTestClass(3)
        val str = Json.encodeToString(o1)
        val o2 = Json.decodeFromString<OuterTestClass>(str)
    
        assertEquals(o1.x, o2.x)
        assertEquals(o1.inner.y, o2.inner.y)
        assertEquals(o1.inner.compute(), o2.inner.compute())
    }
    The intermediate JSON string looks like what I would expect: {"x":3,"inner":{"y":5}} I am using Kotlin 1.4.10 and Kotlinx Serialization version 1.0.0-RC. I checked the serialization documentation for any exclusions for inner class support but didn't find anything that looked relevant, and also checked open issues on Github. Does anyone know if this is an intentional unsupported use case, or otherwise a known open issue? Thanks.
    s
    • 2
    • 1
  • s

    sandwwraith

    09/21/2020, 3:36 PM
    📣 kotlinx.serialization
    1.0.0-RC2
    has been released! This RC contains tweaks and changes based on users feedback after 1.0.0-RC. Important highlights: * JSON serial format was moved to separate
    kotlinx-serialization-json
    artifact to keep core lightweight. You may need to update your buildscripts and replace
    -core
    with
    -json
    . *
    encodeDefaults
    is now
    false
    by default because this seems to be a more popular setting. * Fixed several critical bugs (including problems with Android API < 24 and Native ObjC interop). For full changelog and migration guide, see either
    CHANGELOG.md
    in repository or release notes: https://github.com/Kotlin/kotlinx.serialization/releases/tag/v1.0.0-RC2
    🎉 10
    c
    t
    • 3
    • 4
  • r

    Robert Jaros

    09/21/2020, 4:18 PM
    I've filled an issue in the wrappers repository: https://github.com/JetBrains/kotlin-wrappers/issues/346
    b
    g
    • 3
    • 4
  • l

    leandro

    09/24/2020, 1:03 PM
    I’m facing a runtime issue with
    1.0.0-RC2
    (did not happen with
    1.0.-RC
    ) with my custom serializer using Json. It’s minified by the stacktrace contains this piece:
    Caused by: kotlinx.serialization.SerializationException: Serializer for class 'k' is not found.
    Mark the class as @Serializable or provide the serializer explicitly.
    a
    • 2
    • 1
  • s

    Sourabh Rawat

    09/26/2020, 5:49 AM
    How can I serialize a data class into a list ex
    data class Foo(val id: String, val uris: List<String>, val option: Option)
    data class Option(val bar: String)
    
    Foo("123", listOf("123", "345"), Option("abc"))
    into
    ["123", ["123, "345"], { "bar": "abc" }]
    Foo is simply an example. I want to serialize any data class.
    v
    • 2
    • 2
  • i

    Ian

    09/26/2020, 6:12 AM
    Can ProtoBuf serialize a class with nullable properties? I try:
    fun main() {
        @Serializable data class Foo(val nn : Int?)
    
        val s = ProtoBuf.encodeToByteArray(Foo.serializer(), Foo(null))
    }
    But get:
    Exception in thread "main" kotlinx.serialization.SerializationException:
     'null' is not supported in ProtoBuf
    I've also tried using:
    val s = ProtoBuf { encodeDefaults = false }.encodeToByteArray(Foo.serializer(), Foo(null))
    But this doesn't help. Any pointers appreciated.
    v
    • 2
    • 2
  • v

    Venkat , Bangalore , India

    09/27/2020, 6:14 AM
    Hi Everyone.. Could you please help me with below issue.. it works fine in Android, but crashed in iOS...... IDEA Version: IntelliJ IDEA 2020.2.2 (Community Edition) Build #IC-202.7319.50, built on September 15, 2020 sample code: interface IElement{} @Serializable @SerialName("Item") data class ElementImpl:IElement class JsonExporter { suspend fun export(): String { val module = SerializersModule { polymorphic(IElement::class, ElementImpl::class, ElementImpl.serializer()) } val elementsList<ElementImpl> = ... val jsonString = Json { serializersModule = module }.encodeToString(elementsList) return jsonString } } Multiplatform setup: dependencies { //others classpath "org.jetbrains.kotlin:kotlin-serialization:1.4.10" } plugins { id 'org.jetbrains.kotlin.multiplatform' version '1.4.10' id 'org.jetbrains.kotlin.plugin.serialization' version '1.4.10' } sourceSets { commonMain { dependencies { //serialization implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.0-RC2" } } } Error: Exception doesn't match @Throws-specified class list and thus isn't propagated from Kotlin to Objective-C/Swift as NSError. It is considered unexpected and unhandled instead. Program will be terminated. Uncaught Kotlin exception: kotlinx.serialization.SerializationException: Serializer for class 'IElement' is not found. Mark the class as @Serializable or provide the serializer explicitly. On Kotlin/Native explicitly declared serializer should be used for interfaces and enums without @Serializable annotation External Libraries that got added transitively after i added "kotlinx-serialization-json:1.0.0-RC2" Gradle: org.jetbrains.kotlinx:kotlinx-serialization-core-iosx64:klib:1.0.0-RC2 Gradle: org.jetbrains.kotlinx:kotlinx-serialization-core-jvm:1.0.0-RC2@jar Gradle: org.jetbrains.kotlinx:kotlinx-serialization-core-metadata:1.0.0-RC2 Gradle: org.jetbrains.kotlinx:kotlinx-serialization-json-iosx64:klib:1.0.0-RC2 Gradle: org.jetbrains.kotlinx:kotlinx-serialization-json-jvm:1.0.0-RC2@jar Gradle: org.jetbrains.kotlinx:kotlinx-serialization-json-metadata:1.0.0-RC2
    • 1
    • 1
  • j

    Justin

    09/29/2020, 2:35 AM
    Anyone else experienced significant lag times when deserializing JSON with custom serializers on Android, as compared with iOS? We deserialize a ~10kb JSON string in ~90ms on iOS versus anywhere between 200ms and 8 seconds on Android.
    v
    • 2
    • 1
  • c

    coolchandrakumar

    09/29/2020, 5:15 AM
    Facing the exception while trying to convert json to protoBuf message using parseFrom() method
    com.google.protobuf.InvalidProtocolBufferException: While parsing a protocol message, the input ended unexpectedly in the middle of a field.
    at com.google.protobuf.GeneratedMessageLite.parsePartialFrom(GeneratedMessageLite.java:1563)
    Android Project using protobuf lite plugin
    • 1
    • 1
  • v

    Vinod Rai

    09/29/2020, 8:51 AM
    Android
    -keepattributes *Annotation*, InnerClasses
    -dontnote kotlinx.serialization.SerializationKt
    -keep,includedescriptorclasses class com.yourcompany.yourpackage.**$$serializer { *; } # <-- change package name to your app's
    -keepclassmembers class com.yourcompany.yourpackage.** { # <-- change package name to your app's
        *** Companion;
    }
    -keepclasseswithmembers class com.yourcompany.yourpackage.** { # <-- change package name to your app's
        kotlinx.serialization.KSerializer serializer(...);
    }
    The package name is changed,..getting exception .. I am using 1.0.0-RC
    Serializer for class 'e' is not found.
        Mark the class as @Serializable or provide the serializer explicitly.
    Data classes are in shared code. Why progaurd configuration is not working with minify enabled.  can anyone help what I am missing here?
    g
    • 2
    • 1
  • f

    fkrauthan

    10/01/2020, 2:12 AM
    Hey would it be possible to create some sort of "optional" serializer? E.g. Some generic type that can have 3 states (unset; set but null; set with value) and in case the generic type indicates its unset I don't want to include it in the serialization output?
    g
    k
    v
    • 4
    • 16
  • a

    altavir

    10/01/2020, 7:34 AM
    I believe that I already asked this question, but a lot of things changed since then. Is it possible to encapsulate serial module inside serializer, so I could fix how a class subgraph is serialized without manually adding it to a top level serial module each time I add this class to a new structure.
    👀 1
    v
    • 2
    • 2
  • s

    Sourabh Rawat

    10/02/2020, 2:25 AM
    If I have json
    {
      "id": 123
    }
    how can I configure serialization to automatically populate nullable values and lists in class
    data class Foo(val id: Int, val bar: String?, val foobar: List<String>)
    I want json to be converted to
    Foo(id = 123, bar = null, foobar = emptyList())
    a
    v
    • 3
    • 4
  • s

    spand

    10/02/2020, 9:34 AM
    Given a
    kotlinx.serialization.json.Json
    object. Can I ask it if it is configured to serialize a given
    KClass
    or if it will throw an exception when encountering instances of that type ?
    v
    • 2
    • 2
  • t

    Tomas Kormanak

    10/02/2020, 9:52 AM
    Hi, is there a way how to deserialize dynamic structure from JSON? For example I have this class but I don't know the exact structure of
    data
    property.
    @Serializable
    data class Sample(
        val name:String,
        val data: Any
    )
    j
    • 2
    • 1
  • r

    Robert Jaros

    10/04/2020, 2:33 PM
    Anything changed with serialization of enum classes in 1.0.0 on Kotlin/JS? I have the following error when I try to serialize enum class without
    @Serializable
    annotation:
    SerializationException: Serializer for class 'Test' 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
    It works when I use
    @Serializable
    , but the documentation states enum do not need this annotation: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/builtin-classes.md#enum-classes
    s
    • 2
    • 2
  • m

    Matt Toal

    10/05/2020, 8:31 PM
    Any word on when the 1.0.0 non-RC version is projected to be released? No worries if the answer is something along the lines of "It will be released when it is ready", but wanted to check if where public expectations
    t
    g
    • 3
    • 3
  • l

    leandro

    10/06/2020, 11:42 AM
    I’m trying to deserialize a simple sealed class (with one field called
    __type
    and another called
    message
    ) from my api, modeled using Retrofit and a generic response such as
    NetworkResponse<MyResponse, ErrorResponse>
    , in which the
    ErrorResponse
    is the sealed class in question. Analysing the returned type with the debugger shows me that my generic response is
    UnknownError(error=kotlinx.serialization.json.internal.JsonDecodingException: Polymorphic serializer was not found for missing class discriminator ('null')
    JSON input: {"__type":"UserLambdaValidationException","message":"..."})
    I’m using v1.0.0-RC, and unsure how to proceed.
    v
    p
    • 3
    • 13
  • s

    sandwwraith

    10/08/2020, 3:40 PM
    📣 kotlinx.serialization
    1.0.0
    has been released! This is a public stable release. The definitions of stability and backwards compatibility guarantees are located in the corresponding document: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/compatibility.md. We now also have a GitHub Pages site with full API reference: https://kotlin.github.io/kotlinx.serialization/. There are little changes compared to RC2, however, all previously deprecated declarations and migrations were deleted. If you are using RC/RC2 along with deprecated declarations, please, migrate before updating to 1.0.0. You can study changelog (https://github.com/Kotlin/kotlinx.serialization/blob/master/CHANGELOG.md) for help. In case you are using pre-1.0 versions (e.g. 0.20.0), please refer to our migration guide: https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/migration.md.
    🍾 20
    🎉 11
    🚀 4
    b
    e
    +3
    • 6
    • 10
  • t

    tylerwilson

    10/08/2020, 6:14 PM
    Any examples around of creating a custom serializer that can take a custom parameter, like so:
    @DateSerializer(format = "dd/MM/yyy")
    val date: Date
    s
    v
    • 3
    • 4
  • b

    basher

    10/08/2020, 6:17 PM
    Is there a timeline for stability of
    @Serialization(forClass:…
    ?
    v
    • 2
    • 1
  • w

    why

    10/08/2020, 7:51 PM
    Hi, I wanna serialize a List<E> that I implemented, what is the right approach of doing it, using the prebuilt serializers (like ArrayListSerializer, ListLikeSerializer or even AbstractCollectionSerializer), I’m having so much trouble with these classes, can anyone help?
    m
    s
    • 3
    • 7
Powered by Linen
Title
w

why

10/08/2020, 7:51 PM
Hi, I wanna serialize a List<E> that I implemented, what is the right approach of doing it, using the prebuilt serializers (like ArrayListSerializer, ListLikeSerializer or even AbstractCollectionSerializer), I’m having so much trouble with these classes, can anyone help?
m

Mranders

10/09/2020, 7:48 AM
Assuming you want to serialize the list to json, you can do something like this:
@Serializable
class E(val s: String)

fun main() {
    val listOfEs = listOf(E("foo"), E("bar"), E("baz"))
    val eListSerializer = ListSerializer(E.serializer())
    val serialized = Json.Default.encodeToString(eListSerializer, listOfEs)
    println(serialized)
}
Result: [{"s":"foo"},{"s":"bar"},{"s":"baz"}]
w

why

10/09/2020, 8:20 AM
Hi thanks for your reply but this is not what I want exactly, given this
import kotlinx.serialization.encodeToString
 import kotlinx.serialization.json.Json
 
 val listOfEs = listOf(1, 2, 34)
 val serialized = Json.Default.encodeToString(listOfEs)
 println(serialized) // result: [1,2,34]
I wanna be able to do this :
import kotlinx.serialization.encodeToString
 import kotlinx.serialization.json.Json
 
 val myList = MyListImplementation(1, 2, 34)
 val serialized = Json.Default.encodeToString(myList)
 println(serialized) // result: [1,2,34]
I wanna have my list supported just like the native ones : )
the problem is that prebuilt collections serializers are internal : (
given that, maybe there is another way of doing it without rewriting the whole thing?
s

sandwwraith

10/09/2020, 8:59 AM
You can wrap your serializer around instance of prebuilt one. The classes are internal, but we have factory functions like
ListSerializer(...)
👍 1
w

why

10/09/2020, 9:56 AM
back.. thanks a lot that’s what I was looking for : )
View count: 3