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

    louiscad

    10/12/2022, 1:13 AM
    Sooo… generics are supported in Protobuf with kotlinx.serialization? I wrote a test case using this, I was surprised and delighted to see it pass!
    @OptIn(ExperimentalSerializationApi::class)
    @Serializable
    data class GenericWrapper<T>(
        @ProtoNumber(1) val name: String,
        @ProtoNumber(2) val content: T,
    )
  • b

    Brent Beardsley

    10/12/2022, 11:31 PM
    I have a class
    @kotlinx.serialization.Serializable
    data class Geolocation(
        val latitude: Double,
        val longitude: Double
    )
    that I'm using to get responses from rest calls. Unfortunately the rest api is not consistent and so in some places I need to use
    lat
    and
    lng
    instead of
    latitude
    and
    longitude
    . What is the best way to handle this? A custom serializer or extend the class and add
    @SerialName
    if that's possible? I'd like to really just have one
    Geolocation
    so I'm leaning towards the custom serializer...
    e
    l
    • 3
    • 3
  • z

    zt

    10/13/2022, 4:12 AM
    Is there some way to remove the names for these inner private fields? They're never mean't to be accessed and are only there so they get added to the serialized output. Its just saying unused variable, which isnt a huge issue but it could be better
    @Serializable
    data class ReplyParams(
        @ProtoNumber(2) val videoId: String,
        @ProtoNumber(4) val commentId: String
    ) {
        @ProtoNumber(5)
        private val unknownParams: UnknownParams = UnknownParams()
    
        @ProtoNumber(10)
        private val unknownNumber: Int = 0
    
        @Serializable
        private class UnknownParams {
            @ProtoNumber(1)
            private val unknownNumber: Int = 7
        }
    }
  • x

    xxfast

    10/13/2022, 4:37 AM
    Re: closed-polymorphic type serialisation, are we able to change the key
    type
    field to something else? to achieve something like
    {
      "typeKey": "owned",
      "status": "open",
      "name": "kotlinx.coroutines",
      "owner": "kotlin"
    }
    z
    e
    • 3
    • 3
  • i

    igor.wojda

    10/13/2022, 2:11 PM
    Hello API is returning data in the following format
    {
      "album": {
        "artist": "Michael Jackson",
        "tags": {
          "tag": [
            {
              "url": "https://www.last.fm/tag/pop",
              "name": "pop"
            },
            {
              "url": "https://www.last.fm/tag/soul",
              "name": "soul"
            }
          ]
        }
      }
    }
    The
    tags
    attribute contains a single child
    tag
    , so some kind of container (
    TrackContainer
    ) class is required to parse this JSON:
    @Serializable
    internal data class AlbumApiModel(
        @SerialName("artist") val artist: String,
        @SerialName("tracks") val tracks: TrackContainer? = null,
    )
    
    @Serializable
    internal data class TrackContainer(
        @SerialName("track") val track: List<AlbumTrackApiModel>,
    )
    Since creation of this class is a bit verbose I wonder if there is a way to parse nested attributes without a need to define
    TrackContainer
    class- something like
    @SerialName("tracks.track")
    @Serializable
    internal data class AlbumApiModel(
        @SerialName("artist") val artist: String,
        @SerialName("tracks.track") val tracks: List<Track>? = null,
    )
    o
    • 2
    • 3
  • z

    zt

    10/16/2022, 4:16 AM
    I'm having some trouble making sense of class inheritance and serialization I have this data structure, which can vary deeper down in the json object The easy way which I've gone is just creating the same data class for each one but then I end up with having the same structure multiple times The ideal way I believe for this case would be to use generics and then that way it could simplify my code a lot (I assume) heres two examples of the data i'm working with
    {
      "contents": {
        "singleColumnBrowseResultsRenderer": {
          "tabs": [
            {
              "tabRenderer": {
                "content": {
                  "sectionListRenderer": {
                    "contents": [
                      {
                        "playlistVideoListRenderer": { ... }
                      }
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    }
    {
      "contents": {
        "singleColumnBrowseResultsRenderer": {
          "tabs": [
            {
              "tabRenderer": {
                "content": {
                  "sectionListRenderer": {
                    "contents": [
                      {
                        "itemSectionRenderer": { ... }
                      }
                    ]
                  }
                }
              }
            }
          ]
        }
      }
    }
  • g

    gts13

    10/16/2022, 3:16 PM
    Let's assume I have the following data class
    @Serializable
     data class Accounts(
         val data: List<Account>
     ) {
    
            @Serializable
            data class Account(
                @SerialName("name")
                val name: String,
                @SerialName("lastname")
                val lastname: String,
            ) 
    }
    The
    Json.encodeToString()
    and
    decodeToString
    returns a JsonObject
    {
      "data": [
        {
          "name": "Mike",
          "lastname": "Ekim"
        },
        {
          "name": "John",
          "lastname": "Nhoj"
        },
    ...
    How can encode the data class to return a JsonArray? Like the following:
    data: [{
          "name": "Mike",
          "lastname": "Ekim"
        }, {
          "name": "John",
          "lastname": "Nhoj"
        },
    ...]
    a
    • 2
    • 1
  • j

    Jan Skrasek

    10/17/2022, 12:07 PM
    1.4.1 artifacts already published, but no master merge nor GitHub released published. Is it an intentional release?
    x
    • 2
    • 3
  • m

    Michal Fudala

    10/17/2022, 1:08 PM
    Hello 👋 I'm wondering why these two compile:
    private inline fun <reified K, reified V> JsonElement.decodeOne(key: String): Map<K, V> {
        return jsonObject[key]
            ?.let { Json.decodeFromJsonElement<Map<K, V>>(it) }
            .orEmpty()
    }
    private fun <K, V> JsonElement.decodeOne(key: String): Map<K, V> {
        return jsonObject[key]
            ?.let { Json.decodeFromJsonElement<Map<K, V>>(it) }
            .orEmpty()
    }
    but only the first one works at runtime. Wouldn't it be possible to check this at compile time. The same way it's done (screenshot) for
    Json.decodeFromJsonElement<K>(smth)
    when
    K
    is generic, but not reified. Or is type-erasure still a problem here?
    • 1
    • 1
  • a

    Achraf Amil

    10/17/2022, 3:03 PM
    👋 Any clue why the
    PLUGIN_IS_NOT_ENABLED
    warning is only shown on IDE and doesn’t log (or fail when
    allWarningsAsErrors
    ) ?
    g
    • 2
    • 3
  • s

    Settingdust

    10/18/2022, 7:23 AM
    The value in
    encoder.encodeSerializableValue(serializers[0]!!(), value)
    will error with type mismatch. Expected
    CapturedType(out X*>)
    but X`<*>`. How to pass the value?
    // An external class from lib
    class X<T>
    
    object XSerializer : KSerializer<X<Int>> {
        override val descriptor: SerialDescriptor
            get() = TODO("Not yet implemented")
    
        override fun deserialize(decoder: Decoder): X<Int> {
            TODO("Not yet implemented")
        }
    
        override fun serialize(encoder: Encoder, value: X<Int>) {
            TODO("Not yet implemented")
        }
    }
    
    // A map to take correct serializer by arg
    val serializers: Map<Int, () ->  KSerializer<out X<*>>> = mapOf(0 to { XSerializer })
    
    object GenericSerializer : KSerializer<X<*>> {
        override val descriptor: SerialDescriptor
            get() = TODO("Not yet implemented")
    
        override fun deserialize(decoder: Decoder): X<*> {
            TODO("Not yet implemented")
        }
    
        override fun serialize(encoder: Encoder, value: X<*>) {
            encoder.encodeSerializableValue(serializers[0]!!(), value)
        }
    }
    There is a link testable. https://pl.kotl.in/VVNMv8Zso
  • a

    Anton Wiblishauser

    10/18/2022, 5:07 PM
    Hi, i have this json file: https://meta.fabricmc.net/v2/versions/loader/1.19.2/0.14.9 and i want to deserialize it. My current approach for this is this: https://pastes.dev/UAKFSC4YQo. The problem is, that it throws this error. https://pastes.dev/tIKiMmCyDQ
    s
    f
    • 3
    • 4
  • s

    Settingdust

    10/22/2022, 1:12 PM
    How to create a serializer for a recursive map? Just like
    class A : Map<String, A>
    . The map is guava multimap that not implement the map interface. But can be converted to a map. Below is what I tried. Will throw
    StackOverflowError
    from
    SetSerializer
    object Serializer : KSerializer<A> {
        private val serializer by lazy { MapSerializer(String.serializer(), SetSerializer(this)) }
        override val descriptor by lazy {
            SerialDescriptor(
                "A",
                serializer.descriptor
            )
        }
        override fun deserialize(decoder: Decoder) =
            A(Multimaps.newMultimap(serializer.deserialize(decoder)) { setOf() })
        override fun serialize(encoder: Encoder, value: A) =
            serializer.serialize(encoder, value.asMap().mapValues { it.value.toSet() })
    }
    e
    • 2
    • 5
  • c

    christophsturm

    10/23/2022, 1:01 PM
    is there an official short name for kotlinx-serialization, one that is valid as a package name?
    kxser
    seems to be used by some libs but imo thats not very catchy.
    kotlinxserialization
    is hard to read. can anyone think of something nicer?
    e
    r
    • 3
    • 12
  • a

    Alex Mihailov

    10/24/2022, 8:35 AM
    Hi all! I'm trying to build a project in my kotlinx.serialization fork, branch dev and I get an error when run
    gradlew clean build
    :
    \projects\kotlinx.serialization\core\jvmMainModule\src\module-info.java:4: error: package is empty or does not exist: kotlinx.serialization
        exports kotlinx.serialization;
                       ^
    JDK liberica 11.0.16, language level 11. When rebuild project, the error does not reproduce. Has anyone encountered this problem and knows the solution?
    s
    • 2
    • 1
  • m

    Mohit Sharma

    10/25/2022, 8:05 PM
    Any headup on how fix this issue ?
    Caused by: kotlinx.serialization.json.internal.JsonDecodingException: Polymorphic serializer was not found for missing class discriminator ('null')
    2022-10-25 20:31:56.910 4548-4548/com.socialpillars.ngo E/AndroidRuntime: JSON input: .....te_time":"2022-03-30T06:43:29.433318+05:30","type":"post"}]}
    data class Posts(
        @SerialName("uuid") val postId: String,
        @SerialName("description") val description: String,
        @SerialName("likes_count") var likesCount: Int,
        @SerialName("images") private val _images: List<Image>,
        @SerialName("user") val user: User,
        @SerialName("is_liked") var isLiked: Boolean,
        @SerialName("create_time") private val _eventStartTime: String,
        var isMyPost: Boolean = false
    )
    data class FeedItem(
        @SerialName("post") var posts: Posts?,
        @SerialName("event") var events: Events?,
        @SerialName("type") var type: FeedType
    )
  • z

    zt

    10/26/2022, 2:06 AM
    Is there any way to implement a class like this, without having to override its parameters and still getting them serialized?
    @Serializable
    open class Test<T>(
        val test: T
    )
    
    @Serializable
    class TestImpl : Test<String>()
    // This doesn't work cause it needs the parameter
    b
    • 2
    • 1
  • a

    Assaf Shouval

    10/26/2022, 7:22 AM
    I want to Serialize and Deserialize a Map<String, *>: i.e. value can be any type (known at compile time), I would like to enforce that the types added to the Map have a serializer. How do you recommend to do it?
  • l

    Landry Norris

    10/26/2022, 5:19 PM
    I’m receiving a JSON with several arrays: foo1, foo2, foo3, etc. with different numbers in the name. I’d like to have a single foo array that contains all of these. Is there an easy way to do this? Right now, I just have a class that contains optional foo1: Array, foo2: Array, etc and a method to convert it to another class with foo: Array, but I’d like to skip the conversion if possible.
    e
    • 2
    • 3
  • e

    Emil Kantis

    10/26/2022, 8:29 PM
    I've started working a bit on a set of standard serializers for KotlinX Serialization together with aSemy. Project is currently super early in its lifecycle, but it would be fun to have some input and feature requests from people who'd consider using it 🙂 Feel free to raise an issue, watch or ⭐ it here Currently we have support for various jdk-specific types such as
    LocalDateTime
    ,
    Instant
    ,
    UUID
    ,
    URL
    , but also have multiplatform support for serializing enums by their ordinal value.
  • c

    Christian Würthenr

    10/28/2022, 5:35 AM
    Quick question about JSON serialziation. I receive this beautiful JSON
    {"actual":"","target":null}
    but both values are supposed to be
    Float?
    . I already use
    coerceInputValues
    to allow string values to be parsed but the
    ""
    doesn’t get translated to
    null
    or something. Is there a way I can tell Kotlin to use the default value if it can’t deserialize something?
    • 1
    • 2
  • z

    zt

    10/29/2022, 5:48 AM
    I'm using the code below to serialize the responses from the API into proper strings but I'm getting an error like this
    Expected JsonPrimitive at text, found {"runs":[{"text":"All"}]}
    I'm not sure what I'm doing wrong here
    internal typealias ApiText = @Serializable(ApiTextSerializer::class) String
    
    private class ApiTextSerializer : KSerializer<String> {
        override val descriptor: SerialDescriptor = buildClassSerialDescriptor("ApiText")
    
        override fun deserialize(decoder: Decoder): String {
            val input = decoder as JsonDecoder
    
            return input.decodeJsonElement().jsonObject["runs"]!!.jsonArray.joinToString(separator = "") {
                it.jsonObject["text"]!!.jsonPrimitive.content
            }
        }
    
        override fun serialize(encoder: Encoder, value: String) {
            throw RuntimeException("Serialization is not needed")
        }
    }
    r
    • 2
    • 5
  • a

    Assaf Shouval

    10/30/2022, 6:00 PM
    I want to serialize BigInteger as a class but, I fail to get some none primitive value: here's my code:
    object BigIntegerSerializerForMeta :
        KSerializer<BigInteger> {
    
        override val descriptor: SerialDescriptor = buildClassSerialDescriptor("BigIntSerializer") {
            element("value", PolymorphicPrimitiveSerializer(String.serializer()).descriptor)
        }
        const val radix = 16
        override fun deserialize(decoder: Decoder): BigInteger {
            return BigInteger(decoder.decodeSerializableValue(String.serializer()), radix)
    
        }
        override fun serialize(encoder: Encoder, value: BigInteger) =
            encoder.encodeSerializableValue(String.serializer(), value.toString(radix))
    }
    I get {"1234567890"} instead of {"type":BigIntSerializer,"value":"1234567890"}
    d
    • 2
    • 6
  • e

    Erik

    10/31/2022, 8:39 AM
    Why is `allowStructuredMapKeys` (docs)
    false
    by default? Is it because serializing a map to an array is non-standard behaviour? And throwing an exception (if
    false
    ) is standard behaviour?
    j
    • 2
    • 1
  • s

    Sunil Kumar

    11/01/2022, 2:43 PM
    Hi guys, with kotlinx serialization i am facing following error in kmm project
    Caused by: kotlinx.serialization.json.internal.JsonDecodingException: Polymorphic serializer was not found for missing class discriminator ('null')
    Not able to find any solution for that. Can anyone help me with that. Tried some solutions from google and stackoverflow, but didnt worked.
    e
    a
    • 3
    • 2
  • a

    Assaf Shouval

    11/02/2022, 2:35 PM
    Polymorphic serializing a Pair inside polymorphic serialization of Any
    val module = SerializersModule {
        polymorphic(Any::class) {
            subclass(Int::class, PolymorphicPrimitiveSerializer(Int.serializer()))
            subclass(String::class, PolymorphicPrimitiveSerializer(String.serializer()))
            subclass(Pair::class, PolymorphicSerializer(Pair::class))
        }
        polymorphic(Pair::class) {
            PairSerializer(Int.serializer(), String.serializer())
        }
    
    }
    
    val format = Json { serializersModule = module }
    val mm = mapOf<String, Any>()
            .plus("intString pair" to 5 to "FIVE")
    How to declare the Serialization for the Pair?
    • 1
    • 2
  • e

    Emil Kantis

    11/03/2022, 11:02 PM
    I'm a bit confused by the
    PrimitiveSerialDescriptor
    . The docs state:
    For primitive serialization, the PrimitiveSerialDescriptor function must be used with a unique name of the type that is being serialized.
    But this KDoc example sets the name to
    kotlinx.serialization.LongAsStringSerializer
    , which is the name of the serializer, not the type being serialized. Which one is correct?
  • e

    elect

    11/04/2022, 9:09 AM
    sorry for the newbie question, I need to parse an xml into a (data) class and I'm using xmlutil
    <?xml version="1.0" encoding="UTF-8"?>
    <registry>
        <comment>
    Copyright 2015-2022 The Khronos Group Inc.
    
    SPDX-License-Identifier: Apache-2.0 OR MIT
        </comment>
    I started with
    fun parse(text: String) {
        val format = XML {}
        val registry = format.decodeFromString<Registry>(text)
    }
    
    @Serializable
    data class Registry(
        val comment: String,)
    but I get:
    Execution failed for task ':generateCode'.
    > Could not find a field for name (vkk.Registry) Registry/comment (Element)
    candidates: Comment at position Line number = 3
    What am I missing?
  • g

    George

    11/04/2022, 10:39 AM
    Hello folks, question can someone help/point to docs me understand why this does not work? Thanks in advance for any answers !
    @file:UseSerializers(UrlSerializer::class)
    
    // using serializer explicitly works
    val url = URL("<https://test>")
    val protobytes = ProtoBuf.encodeToByteArray(UrlSerializer, url)
    val result = ProtoBuf.decodeFromByteArray(UrlSerializer, protobytes)
    
    // use file serializer, this fails
    shouldThrow<SerializationException> {
        val protobytes2 = ProtoBuf.encodeToByteArray(url)
        val result2: URL = ProtoBuf.decodeFromByteArray(protobytes)
        println(result2)
    }
    
    // use typealias serializer, this also fails
    shouldThrow<SerializationException> {
        val url2: UrlAsString = url
        val protobytes2 = ProtoBuf.encodeToByteArray(url)
        val result2: UrlAsString = ProtoBuf.decodeFromByteArray(protobytes)
        println(result2)
    }
    
    // using inside data class works (like in the guide)
    @Serializable
    data class TestUrl(val value: URL)
    
    val testUrl = TestUrl(url)
    val proto = ProtoBuf.encodeToByteArray(testUrl)
    val resultUrl: TestUrl = ProtoBuf.decodeFromByteArray(proto)
    println(resultUrl)
    In case, when using file serializer or global how come it throws: cannot find serializer for URL ?
    e
    • 2
    • 2
  • i

    IsaacMart

    11/04/2022, 3:53 PM
    Any help with custom Type converters using koline serialization?
    • 1
    • 1
Powered by Linen
Title
i

IsaacMart

11/04/2022, 3:53 PM
Any help with custom Type converters using koline serialization?
After a break i was able to solve the challenge. I missed out of providing workCategory Typeconverter.:melting_face:
View count: 10