KV
07/26/2021, 11:45 AMconst val START_ACTION = "start"
enum class Actions(val info: String) {
START(START_ACTION)
}
---------------------------------------------------------------------------
@Serializable
data class ActionRequest(
@SerialName("action_type")
val actionType: Actions ----> enum is compulsory to use here
)
---------------------------------------------------------------------------
val actionRequest = ActionRequest(actionType = START)
---------------------------------------------------------------------------```
Here, I am getting output is "START" rather than "start".
Can someone please help me with how to get the value of action here?eygraber
07/28/2021, 5:02 AMclass Test<T>(val t: T) {
val serializer = T::class.serializer() // I know this doesn't work
}
Slackbot
07/29/2021, 7:36 AMMatthew Cachia
08/01/2021, 6:17 AMEither<L, R>
construct which is a third party (and therefore created its own serialiser: EitherSerializer
).
However, deserialising straight to it doesn't work. typealias doesn't work either.
// yields kotlinx.serialization.SerializationException: Serializer for class 'Either' is not found.
Json.decodeFromString<Either<SchemaObject, ReferenceObject>>(json)
// yields kotlinx.serialization.SerializationException: Serializer for class 'Either' is not found.
typealias EitherAlias<L, R> = @Serializable(EitherSerializer::class) Either<L, R>
...
Json.decodeFromString<EitherAlias>(json)
// works fine!
@Serializable
data class NestedInAClass(val schema: @Serializable(EitherSerializer::class) Either<SchemaObject, ReferenceObject>)
...
Json.decodeFromString<NestedInAClass>(json)
It looks like it would work only if it is nested within a serialised class. I don't see why typealias wouldn't work. Any help would be appreciated!ankushg
08/03/2021, 12:45 AM{
foo: [1, 2, 3]
}
Is there a way to deserialize that into
data class MyClass(val foo: String)
and have the value of MyClass.foo
be the string "[1, 2, 3]"
?Waqas Tahir
08/03/2021, 4:43 PMWaqas Tahir
08/04/2021, 6:56 AMabstract class MapNode {
// Node Properties
var isGroup by mutableStateOf(false)
var colorIndex by mutableStateOf(0)
// Node Children
@Serializable(with = SnapshotStateListSerializer::class)
var left = mutableStateListOf<MapNode>()
}
How can I write a Custom Serializer for this class ?? that serializes all these properties ! (including delegated properties)Bruno Medeiros
08/06/2021, 4:34 PM$serializer
synthetic property that is created for each class/companion. If I remove all my @Serializable
, my module reduce its size by 80%. JVM an iOS are fine, but I can't pay that price in JS.
Question is:
Is there a way to disable kotlinx-serialization $serializer
generation just in the JS backend? If I could disable it just in JS, I could still use the kotlinx-serialization
serializer for all backends and I'd roll my own for JS, but I would still be able to use my data classes in JS.Marc Knaup
08/06/2021, 7:45 PMaltavir
08/07/2021, 10:45 AMEmiliano Schiavone
08/09/2021, 10:41 PMprivate val contentType = "application/json".toMediaType()
private val json = Json {
prettyPrint = true
ignoreUnknownKeys = true
}
..
..addConverterFactory(json.asConverterFactory(contentType))
But i cannot see the logs on logcat screen. Any idea how to display it?johnaqel
08/11/2021, 1:32 AMGene Cahill
08/11/2021, 10:50 PMWaqas Tahir
08/12/2021, 2:05 PMclasspath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
how can I avoid this , my project does not need serialization library , only the dependent library needs it
so anyone if uses my library does not need to put classpath like thischristophsturm
08/13/2021, 11:13 AMF0X
08/13/2021, 11:49 AMList<Byte>
, so a specific generic type. Is it possible, and if so how?nschulzke
08/13/2021, 3:51 PM// in package com.example.platform
interface Event
// in package com.example.customer
@Serializable
sealed class CustomerEvent : Event {
object CustomerEvent1
...
}
// in package com.example.supplier
@Serializable
sealed class SupplierEvent : Event {
object SupplierEvent1
...
}
I would like to be able to serialize/deserialize Event
, but I don't really want to have all the event trees in one package, so using one big sealed class
hierarchy doesn't work well.
Does anyone have any idea how to go about registering Event
as polymorphically serializable?Nikita Khlebushkin
08/14/2021, 10:35 PMW/System.err: kotlinx.serialization.SerializationException: Serializer for class 'Companion' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
The place I am trying to use:
try {
api.createAccount(Account(handle = "some", displayname = "Some name"))
} catch (e: Exception) {
e.printStackTrace()
}
And the class itself:
import kotlinx.serialization.Serializable
@Serializable
data class Account(val handle: String, val displayname: String)
Ktor's HttpClient config contains:
install(JsonFeature) {
serializer = KotlinxSerializer(Json {
ignoreUnknownKeys = true
encodeDefaults = true
useAlternativeNames = false
})
}
In my build.gradle.kts of the module I have:
plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
id("com.squareup.sqldelight")
id("com.android.library")
}
kotlin {
...
sourceSets {
val serializationVersion = "1.2.2"
val ktorVersion = "1.6.2"
val commonMain by getting {
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:$serializationVersion")
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
implementation("io.ktor:ktor-client-logging:$ktorVersion")
}
}
val androidMain by getting {
dependencies {
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
}
}
val iosMain by getting {
dependencies {
implementation("io.ktor:ktor-client-ios:$ktorVersion")
}
}
}
}
What am I doing wrong?Ayfri
08/15/2021, 1:23 AMdecodeNullableSerializableElement
on a Byte?
value ?
Or in other words, how can I deSerialize a Byte?
?Ayfri
08/15/2021, 4:15 AMval state by mutableStateOf(MyEnum.FIRST_VALUE)
, I want to omit the field if it is equal to MyEnum.FIRST_VALUE
as it is the default one and most used through my code, but I don't understand how 🤔
I have a custom Serialiazer and I'm encoding the value as Nullable and I've set encodeDefaults = false
in my Json configuration, but it's still emitted and when I try to read the JSON I get this
Exception in thread "AWT-EventQueue-0" kotlinx.serialization.json.internal.JsonDecodingException: Unexpected JSON token at offset 8: Expected numeric literal
JSON input: [{"task":"test #1","state":null},{"task":"test #2","state":null}]
Jesse Hill
08/17/2021, 7:23 PMankushg
08/18/2021, 7:14 PMtype
as the discriminator, but we'd also like to have a val type
inside the deserialized object, containing the same content as type
from the serialization logic.
I imagine that the tricky part here would be that there's no guarantees that the val type
would always line up with the class discriminator when serializing or mutating a deserialized class?Ashley Figueira
08/19/2021, 10:48 AMsealed class ApiResponse {
data class Success(val fields: String) : ApiResponse()
data class Error(val errorCode: String, val errorMessage: String): ApiResponse()
}
Is there any tutorial on how to do something like this?altavir
08/20/2021, 5:01 PM{ $ref: 2}
instead of some of its nodes. My task is to find those nodes and replace them by objects those refs are referencing to. The problem is that I do not know in advance on which level those refs will appear. It is quite easy to create either custom decoder o custom serializer that checks specific node and replaced it if it is ref, but I can't see a way to propagate this decoder/serializer logic recursively to sub-nodes. Does anybody have a similar expirience? I know that is is possible to do in @pdvrieze's XML processor by applying custom decoder logic to configuration.Emil Kantis
08/23/2021, 12:56 PMKSerializer<T>
? Use case would be writing a BigDecimal without precision-loss as { "myValue": 0.12345 }
, but without using a Double along the way. Likewise it would be nice to be able to use a decoder.decodeUnquotedString
or something, to parse the above value into a string rather than double without needing to set isLenient
Tomas Kormanak
08/24/2021, 7:54 AMEmil Kantis
08/24/2021, 9:06 AMRichard Gomez
08/24/2021, 4:04 PM["v1", "v2", "v3"]
) as a data class?
@Serializable
data class VersionResponse(val versions: List<String>)
I've made several attempts with JsonTransformingSerializer
, but no dice! 😔Gene Cahill
08/25/2021, 10:23 PMNathan Bedell
08/27/2021, 3:08 PM