48 questions
2
votes
1
answer
266
views
How to format LocalDate with custom pattern in kotlinx-datetime (equivalent to Java DateTimeFormatter)?
I'm migrating from Java's java.time API to kotlinx-datetime and need to format dates with custom patterns. In Java, I was using:
date.plusDays((number - 1).toLong())
.format(DateTimeFormatter....
1
vote
0
answers
83
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 ...
1
vote
1
answer
700
views
Pretty-Print a JsonElement of kotlinx
I have a kotlinx JsonElement at hand, and I want to pretty-print it.
How do I do that? The only methods I see for pretty-print need a data class, but my element does not fit any specific class.
//EDIT:...
1
vote
1
answer
1k
views
How to handle Any serialization with kotlinx serialization
I have a JSON response with a parameter which may be of different types depending on the enum value of another parameter.
Example JSON:
[
{
"type":1,
"value":&...
0
votes
0
answers
124
views
How To Receive Bytes From Server?
the sever is sending me an array of arrays of bytes [[Byte]] or List<List<Byte>>. A small sample looks like this [[102, 222, 111], [92, 22, 111], [142, 122, 32]] when writing this into a ...
4
votes
2
answers
2k
views
How do I provide a page template in kotlinx-html?
I would like to generate a bunch of HTML files with kotlinx-html and I want to start each file with the same template. I would like to have a function for the base structure and provide a lamda to ...
6
votes
0
answers
6k
views
HTML in Jetpack Compose Text
I tried to enable HTML strings, especially with links e.g.:
"We are a <a href="/about/about_team.htm">team</a> of professionals working hard to provide free learning content....
0
votes
1
answer
1k
views
Parse a dynamic nested JSON into Map<*, *> using Kotlinx.serialization
I need to parse any dynamic JSON (In the Kotlin Multiplatform project) to key-value pair and convert it to a nested list after. I started with the default .toMap() function, but it can't go deeper to ...
1
vote
2
answers
3k
views
java.util.Date to kotlinx.datetime.LocalDateTime
I have a value of type java.util.Date which was obtained from a legacy third-party API. Is there a direct way of converting it to kotlinx.datetime.LocalDateTime? I know how to do it only in a ...
0
votes
1
answer
5k
views
Unresolved reference: kotlinx (Android Studio)
Unresolved reference: kotlinx.
3
votes
1
answer
2k
views
How to compare actual and expected serialization result in kotlinx?
Note: I'm completely new to the Kotlin / JUnit ecosystem, so please bear with me if the question is missing something basic.
I'm working on a JSON-based file format. In the unit/integration tests, I'd ...
4
votes
1
answer
2k
views
kotlinx serialization — best way to do polymorphic child deserialization
I have a Json input like:
{
"type": "type_1",
"data": {
// ...
}
}
data field can vary depending on type.
So, I need a deserializer, that looks on type (...
0
votes
1
answer
2k
views
JsonDecodingException on valid Json with Ktor/Kotlinx
Why I get the following error at offset 6 with the following code. It makes an HTTP Request, gets a Json back, should go through the Json and create the object IMDBInfo. The json is valid, obviously ...
3
votes
2
answers
7k
views
Custom KotlinX Serializer for List class
I want to make a custom List serializer that will parse invalid json arrays safely. Example: list of Int [1, "invalid_int", 2] should be parsed as [1, 2].
I've made a serializer and added it ...
4
votes
3
answers
2k
views
How do I create the onClick function for a button with Kotlinx.html?
I am using Kotlin's html library kotlinx.html for dynamic html building.
I want to create a button which triggers a function when clicked. This is my current code:
class TempStackOverflow(): Template&...
2
votes
1
answer
3k
views
Kotlinx serialization - How to write a data class for an unknown field name
I try to write a data class for the following JSON response from a public API:
{
"error": [],
"result": {
"AAVE": {
"aclass": "currency",...
1
vote
0
answers
372
views
kotlinx serialization. Deserialize generic parameter trouble
I am migrating my project serialization client from GSON to KotlinxSerialization and Faced a problem:
All responses from API inherit an abstraction class for example:
abstract class BaseResponse <T&...
3
votes
1
answer
2k
views
KotlinX Serialization of Built-in Classes
Kotlinx docs don't seem to cover this, I am wondering if there is a way to write a custom Serializer for an existing class. In my case, I need to serialize PointF and Color. For PointF, I have done ...
9
votes
4
answers
9k
views
Why do I get ‘does not implement abstract member’ warning while using kotlinx.android.parcel.Parcelize?
I am getting this error while trying to read the bundle from another fragment where I am sending the NewVehicle object.
Error : Class 'NewVehicle' is not abstract and does not implement abstract ...
3
votes
1
answer
2k
views
how to compile kotlinx.serialization libraries on the command line?
This is very close to what I'm trying to accomplish. How to compile and run kotlin program in command line with external java library
I really want to learn how to compile and run simple code that ...
2
votes
0
answers
331
views
Preventing HTML encoding in kotlinx.html DSL
I am using kotlinx.html DSL to generate an HTML DIV. One of the DIV's attributes is a URL with & in it. e.g. Parameter url below is https://www.example.com?a=1&b=2
fun createDiv(url: String): ...
6
votes
1
answer
4k
views
android kotlin multiplatform kotlinx.serialization works on debug but does not work on release version
We are making our next project in the company with kotlin multiplatform. Everything worked fine until I tried to create a release version for android to beta test. I got this error in release ...
1
vote
1
answer
3k
views
kotlinx de/serialization sealed class/enum
Writing chat app using kotlin,
historically from nodejs I have websocket json objects in/output format:
{"action": "join:chatroom", "payload", "chatroom-name"}
{"action": "leave:chatroom", "payload", ...
3
votes
1
answer
2k
views
Receiving NoClassDefFoundError when invoking generated serializer() method
I’m getting a NoClassDefFoundError when trying to invoke the Foo.serializer() method on a @Serializable class.
Here's my test case:
@Serializable
data class Foo(val data: String)
val jsonString = ...