Questions tagged [kotlinx.serialization]

Kotlin serialization generated code to serialize objects without reflection only by marking a class with @Serializable annotation.

Kotlin serialization consists of a compiler plugin, which automatically produces visitor code for classes, and runtime library, which uses generated code to serialize objects without reflection.

  • Supports Kotlin classes marked as @Serializable and standard collections.
  • Supports JSON, CBOR, and Protobuf formats out-of-the-box.
  • The same code works on Kotlin/JVM, Kotlin/JS, and Kotlin/Native
262 questions
0
votes
1 answer

Using a KClass reference as a reified parameter to deserialize from JSON

I'm trying to implement a general serialization framework to convert outgoing and incoming messages to json using the kotlinx serialialization. I'm developing a multiplatform app, so I'm trying to get it to run on KotlinJVM and KotlinJS. For this, I…
Geosearchef
  • 600
  • 1
  • 5
  • 22
0
votes
1 answer

How to intercept deserialisation with kotlinx.serialization

For example, I have JSON { "url": "//n.ya.com" } In order to deserialize, I define the data class @Serializable data class Foo( @SerialName("url") val link: String, ) After deserializing the Foo object has foo.link with "//n.ya.com" How…
TeeTracker
  • 7,064
  • 8
  • 40
  • 46
0
votes
1 answer

Json$Default cannot be cast to kotlinx.serialization.json.Json

Problem with kotlinx.serialization and running test in androidTest. Lib version: org.jetbrains.kotlinx:kotlinx-serialization-json:1.0.1 org.jetbrains.kotlin:kotlin-stdlib:1.4.10 My instance of Json: Json(Json.Default) { serializersModule =…
KolinLoures
  • 130
  • 2
  • 10
0
votes
1 answer

Kotlinx Serialization @Body converter error while using HashMap with Any type

I am using Kotlinx Serialization with Retrofit and try to send params at Body via HashMap like below @POST("post") suspend fun sendPost(@Body params : HasMap) : GenericResponse But it gives this error…
ysfcyln
  • 2,857
  • 6
  • 34
  • 61
0
votes
1 answer

Decoding and encoding strings for kotlinx.serialization.properties

I'm currently struggling with the experimental KXS-properties serialization backend, mainly because of two reasons: I can't find any documentation for it (I think there is none) KXS-properties only includes a serializer / deserializer, but no…
0
votes
1 answer

Is there a way to completely swap out the way serialization is handled with Apache Beam?

I'm using Kotlin with Apache Beam and I have a set of DTOs that reference each other and all serialize great for any encoder with Kotlinx Serialization. When I try to use them with Beam I end up having issues because it's looking for all objects,…
0
votes
0 answers

How to add TAG on CBOR object and ByteString using kotlinx.serialization

How to add TAG on CBOR object and ByteString using kotlinx.serialization Example…
0
votes
2 answers

Validate that the values ​of List exist in Json Object and return True or False

I am trying to validate if props:List values ​​exist with message:String and return if the value is true or false. fun main() { val message = """ { "id": "xxxxx", "action": "Do", …
John Snow
  • 3
  • 3
0
votes
1 answer

How Serialize nested class with kotlinx.serialization

I need get breadType property from Sandwich class. I have 2 clases both serializable: @Serializable class MyFood { var name: String? = null var price: Int? = null var sand: Sandwich? = null } @Serializable class Sandwich{ var…
Andy
  • 751
  • 1
  • 12
  • 25
0
votes
0 answers

Kotlinx Serializer and single-value domain types

I love to use single-value types for e.g. IDs. How can I tell Kotlinx Serializer to consider such types as regular fields, not objects? Example: data class User( val id: UserId, val name: String, ) should be serialized to: { id: 123, …
igr
  • 10,199
  • 13
  • 65
  • 111
0
votes
1 answer

Receive Map in ktor server using kotlinx.serialization

I have a Ktor server running with kotlinx.serialization as it's json (de)serializer I send my Ktor a message like this one: { "Brick(partNumber=004229, partName=Sticker Sheet for Set 295-1, dataSource=Rebrickable, brickImage=null, categoryID=58)":…
Typhaon
  • 828
  • 8
  • 27
0
votes
2 answers

Convert from String of ByteArray to String

I am trying to convert string to UTF-8 and store it in shared preferences but after getting its value I can't convert string which contains byte array to string var myString ="hello world" var bytes :ByteArray = myString.toUtf8Bytes() value of…
Mohamed Ali
  • 103
  • 1
  • 2
  • 9
0
votes
0 answers

Choosing sealed subclass based on field value in Kotlinx Serialization

Is there a way to distinguish between Successful and Failed responses based on the value of ok field in a response JSON? @Serializable sealed class Response { @Serializable data class Successful( @SerialName("ok") val ok:…
madhead
  • 31,729
  • 16
  • 153
  • 201
0
votes
1 answer

How convert a JSON of a arrayOf JSONArray to an Object

I have the following JSON array: [ [ { "body": "Text", "bodyType": "Text", "nameType": "Text", "makeDisplay": "Acura" } ], [ { "body": "text", "bodyType": "text", "nameType": "text", …
Gilberto Ibarra
  • 395
  • 1
  • 3
  • 8
0
votes
2 answers

Parsing empty object with kotlinx.serialization

I am struggling to understand how to parse an empty object {} with the experimental kotlinx.serialization library. The complication arises when in fact an API response can be one of; { "id": "ABC1", "status": "A_STATUS" } or {} The data…
BrantApps
  • 6,362
  • 2
  • 27
  • 60
1 2 3
17
18