301 questions
2
votes
2
answers
105
views
(De-)Serializing with Nested Closed Polymorphism
In this thread, (de-)serializing a nested polymorphic object is described for open (runtime) polymorphism. How can the same be achieved for closed (static) polymorphism? That is, how can a ...
1
vote
0
answers
72
views
Kotlin serialize simple class with explicit Serial Name
I've tried to use kotlinx.serialization with the third party Yaml plugin from @charleskorn.
In the past I already did something with Python using pyyaml, where I explicitly set a custom yaml_tag for ...
0
votes
0
answers
64
views
Why is Spring's @Cacheable 2x faster than my manual Redis logic?
I'm working on a Spring WebFlux + Kotlin + Redis project and noticed a performance gap between two caching approaches. Specifically, using @Cacheable with a custom serializer is significantly faster (~...
0
votes
0
answers
77
views
How to parse a BIG JSON with kotlinx.serialization in Compose Multiplatform
I have found such kinds of error while calling Web Apis when json response is too large.
Throwing OutOfMemoryError "Failed to allocate a 104643040 byte allocation with 25165824 free bytes and ...
1
vote
1
answer
72
views
How to convert between kotlinx.serialization.json.JsonElement and jooq.JSON?
I want to use the standard kotlinx JsonElement in my data models but translate between jooq.JSON as necessary. Can I do this without going through string serialization?
0
votes
1
answer
43
views
Ktor changed value Double to scientific notation in KMP
Performing a deserialization of a response from a restful service we get back a decimal data where we try to receive it as a Double, however when operating it, it remains as scientific notation for ...
0
votes
0
answers
121
views
Serializer for class 'Result' is not found. Please ensure that class is marked as'@Serializable' and that the serialization compiler plugin is applied
I just learn ktor-client and kotlinx.Serialization for my personal project, but then I found this error.
kotlinx.serialization.SerializationException: Serializer for class 'Result' is not found....
0
votes
2
answers
145
views
How to omit wrapper class when deserializing API response with Kotlin Serialization
I'm using KTOR as a Http Client for my CMP app. I'm wondering if somehow I can omit wrapper class when fetching data from an API and directly load them into the DTO.
Below is my setup:
API response:
&...
0
votes
0
answers
54
views
Get SerialName param from child class in Kotlin kotlinx serialization
I have a parent class RequestFieldResponseBody and two classes that inherit from it (CreateRequestFieldBody and EditRequestFieldBody). I would like to make it so that depending on the child class my ...
0
votes
1
answer
49
views
Deserialize Kotlin Object Based on Enum Property
I'm working on an Android app where I get some data from an API with two properties - one is an enum that describes the data, and the other is the value. The problem I'm having is that the value can ...
2
votes
1
answer
108
views
`kotlinx-serialization`: How to handle default values in custom format implementation
Context
versions in use
kotlin: 2.0.20
kotlinx-serialization: 2.0.20
kotlinx-io: 0.5.4
I've been following the kotlinx-serialization Custom formats guide to implement a custom binary protocol and ...
0
votes
0
answers
116
views
Kotlinx Serialization: CBOR deserialization without deserialization strategy?
I would like to deserialize a generic cbor object using kotlinx-serialization, without knowing much about its structure. Basically an equivalent to a JsonObject, but for Cbor.
Is it possible to ...
0
votes
1
answer
110
views
Ktor - Reading field '_id' failed expected STRING type but found: OBJECT_ID when using @Serializable with MongoDB
Problem
While integrating MongoDB with a Ktor server using @Serializable for data classes, I encountered the following error:
Reading field '_id' failed expected STRING type but found: OBJECT_ID
The ...
0
votes
0
answers
43
views
How to defer/delay parsing using kotlinx.serialization?
I am currently looking for a way to partially parse json and postpone parsing of certain structures. In other words, I want to indicate that field should be kept as rawJson / string even though it is ...
4
votes
2
answers
821
views
Android Compose Typesafe navigation: Passing a List
I want to pass a list of objects to another composable screen through Typse safe navigation but I get this error:
Route com.home.ui.OwnerGraph.FirstLogin.FirstLoginScreen2 could not find any NavType ...
0
votes
0
answers
17
views
Kotlinx Serialization: Supporting deserialization for list or just a single element? [duplicate]
I have a list value in a data class that, when only one element is present, may be serialized by only serializing that one element. The serialized value may therefore be a serialized list of elements ...
1
vote
0
answers
149
views
Is there anything to do in proguard while using kotlinx serialization?
I am using Kotlinx serialization in my KMP project.
This is the plugins section of the build.gradle file for shared module:
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins....
3
votes
1
answer
643
views
Kotlin Serialization: MissingFieldException with Navigation Component and Default Values
I'm implementing navigation in a Jetpack Compose app using the Navigation Component and experiencing serialization issues. I have two related problems:
When I remove default values from my User data ...
0
votes
1
answer
66
views
Extend existing Hibernate Entity as Android Room Entity with Kotlin Serialization annotation
I need to utilize an existing database structure which has Entity classes compatible with JPA (Jakarta Persistence API) for use in Spring Boot via the Hibernate ORM. I want to basically copy this ...
1
vote
0
answers
88
views
Kotlin custom serialization - Linear json structure for nested data classes
I have a couple of data classes like below
data class Base (
val prop1: String,
val prop2: String
)
data class Derived (
val base: Base,
val prop3: String
)
The serialized form of Derived ...
0
votes
0
answers
91
views
How to deserialize a YAML field that can be an object or a string
I am attempting to deserialize a YAML config that has mono/multilingual strings in multiple places, such as:
key1: File
# or
key2:
en_US: File
de_DE: Datei
Using kotlinx.serialization and ...
1
vote
1
answer
102
views
MutableList<T> not being serialized in Kotlin
I'm working on a simple chat server, using kotlin to learn it along the way
I've defined the class to store any message as
@Serializable
data class Message (
var id: Int = messageCounter....
3
votes
1
answer
174
views
Unwrap root value using kotlinx.seralization
Please help me with my problem.
I have to deserialize this file using kotlinx.serialization and kaml
rootElement:
id: 10
name: Some name
to data class
@Serializable
data class SomeData(
val ...
0
votes
2
answers
109
views
How to read JSON array of arrays with mixed values in Retrofit 2?
I'm trying to read the following data from the API:
[
[
1724180400000,
"59191.45000000",
"59597.28000000",
"59137.78000000",
&...
4
votes
1
answer
530
views
Serializing a Kotlin sealed class to a custom JSON structure with kotlinx.serialization
I'm trying to encode a sealed class
json.encodeToString(
Filter.NOT(
Filter.Field(
name = "foo", value = "bar"
...
1
vote
2
answers
105
views
Issue with androidx.navigation library and slash sign
Issue description:
When I try to create custom navigation type and navigate to certain destination in my NavGraph, I get error, which states, that this certain destination cannot be found in the graph....
0
votes
1
answer
55
views
Serialize an object that has parent reference
We've got following structure:
sealed interface Option<T> : IFeature {
var value: T
abstract val parent: OptionContainer
val onChange: (T) -> Unit
fun set(newValue: T) {
...
1
vote
1
answer
164
views
How can I parse a bare "null" response from the server with kotlinx.serialization?
I have a retrofit api interface with a method that looks like this:
@GET("/data")
suspend fun getData(): DataDto?
The server in this instance is returning a 200, and the json response ...
1
vote
1
answer
830
views
Using kotlin kotlinx serialization with generics
Hi everyone I have the following code that I use to serialize into json strings to store in shared preferences
interface Serializer {
public fun <T> serialize(data: T, type: Class<T>): ...
1
vote
2
answers
756
views
How to make a non-backing property serializable in Kotlin
Given a data class like:
@Serializable
data class Person(
val name: String,
val birthDate: Long,
) {
val age get() = /* calculate age */
}
How do I include age in serialization? I know ...
3
votes
2
answers
316
views
Parsing NonEmptyList directly from JSON
Given this JSON: [{"name": "test"}].
Is there a way I can parse this JSON array directly into an Arrow NonEmptyList?
My background is Scala and I'm exploring Ktor + Arrow.
I have ...
0
votes
1
answer
219
views
Kotlin serialization with generics: plugin-generated polymorphic serializer for sealed interface not used
With kotlinx.serialization 1.6.3 on kotlin 1.9.23, I am trying to serialize a type hierarchy (BaseContainer, see example) with a restricted generic type parameter. The generic type itself is a sealed ...
4
votes
0
answers
295
views
How to use kotlinx.serialization without build tools (Maven, Gradle, and so on)?
I'm interested in using kotlinx.serialization in my project, but it wasn't built by any of the build tools (Maven, Gradle, something else). I have access to the classes and annotations, but when it ...
0
votes
1
answer
51
views
How to deserialize polymophic JSON, when type is in out wrapper class?
I have two JSON to deserialize like this:
{ "type": "cat", "animal": { "color": "red", "canJump": true }}
{ "animal": { "...
1
vote
1
answer
269
views
Kotlin Serializing Non-existant Object Returned as Empty String
I'm working with an API that returns an empty string instead of null to indicate the existence of a property, i.e.:
{
"id": 1,
"child": { "foo": "bar" } // ...
2
votes
1
answer
670
views
How to serialize Any with Kotlin serialization?
How can I serialize the below data? This is AppConfig and the value of value could be any type and I can't use Any for serialization.
[
{
"key": "PROFILE_PHOTO",
"...
2
votes
0
answers
147
views
Avoid extra allocations while encoding data as CBOR, using kotlinx.serialization
When using kotlinx.serialization and encoding data as JSON, it's possible to write serialized data directly into an OutputStream, via Json.encodeToStream(SerializationStrategy<T>, T, ...
1
vote
0
answers
103
views
Fatal Exception: java.lang.VerifyError when using Datastore with my own data class on some devices
So I noticed the following crashes at Firebase Crashlytics of my app which happens only for a couple of devices (so rarely) but still it happens:
Fatal Exception: java.lang.VerifyError Verifier ...
2
votes
0
answers
268
views
Kotlin - Optional Generic response in Ktor
I have the following model for an api response:
@Serializable
public data class Response<out T>(
val code: String,
val message: String,
val data: T? = null,
)
The thing is that the ...
0
votes
1
answer
112
views
Handling deserialization of a JSON field of polymorphic type (String or Int)
Our API returns a reserved_stock field that can be either a String or an Int (i.e. "158" or "5"). Since I cannot alter the API's response directly, I have to figure out a way to ...
1
vote
1
answer
1k
views
Kotlin Serialization - polymorphic deserialization of a sealed hierarchy with JsonContentPolymorphicSerializer as an interceptor
I have a need to deserialize JSON models into a strict hierarchy of classes with a strong forwards compatibility requirement.
This is done with closed polymorphism with sealed classes according to ...
1
vote
1
answer
117
views
kotlinx-serialization: how to deserialize JsonArray with diffrent kind of objects into the same Class
I get the following JSON from an API to describe an object with different entries.
{
"entries": [
"Simple Text",
{
"type": "list"...
0
votes
1
answer
338
views
How to deserialize multiple json fields into single object with kotlinx serialization
Consider the following json structure representing a basic check-in information
{
"id": "53481198005",
"date": "1995-01-01 00:00:00",
"latitude":...
0
votes
1
answer
1k
views
How to serialize a class with a generic type using kotlinx.serialization
I have a data class that inherits from a sealed class that I want to serialize into a java.util.ConcurrentLinkedQueue.
@Serializable
sealed class A
@Serializable
data class B : A {
val x: String,
...
0
votes
1
answer
849
views
Collection as String kotlinx.serialization.KSerializer deserialize
I'm using kotlinx.serialization in a KMP sdk for response parsing. I've seen that the properties module can be used to easily create the query map from a given class (I'm using interface inheritance ...
0
votes
1
answer
230
views
Why is this call.receive<T>() deserializing json array items entirely to string type in Ktor?
Consider the following deserialization in Ktor setup context:
A simple model to deserialize JSON requests (aims to receive/store only Strings):
@Serializable
data class TestingDTO(val texts: List<...
1
vote
1
answer
688
views
Parsing a field in Kotlin, which can be a string or an object
I encountered a problem when receiving data from the backend that the resulting field (for example, "somethingField") could be either a String or an Object with two Int lists. How can you ...
2
votes
1
answer
820
views
Serializing a nested sealed class in Kotlin
I am trying to serialize a nested sealed class. Here is an example
@Serializable
sealed class Base {
@SerialName("concrete_property")
val concreteProperty: String = "concrete ...
1
vote
2
answers
2k
views
kotlinx serializer decode snake case to camel case without serial name
Question
Hi I'm new to kotlinx serialization. the json is snake case, and kotlin data class uses camel case. is there a way to parse snake case by using custom serilizer and deserializer?
I know how ...
0
votes
0
answers
65
views
kotlinx advanced deserialization to change object structure
using kotlinx and given a JSON input like {"a": 123, "b": "foo", "c": false}, is there a smart way to have this deserialized into a POJO where the property ...