kotlinx.serialization icon indicating copy to clipboard operation
kotlinx.serialization copied to clipboard

Add default KSerializer for ArrayDeque

Open aSemy opened this issue 5 months ago • 0 comments

What is your use-case and why do you need this feature?

I would like to use an ArrayDeque in a serializable class without extra configuration.

Given that ArrayDeque is a multiplatform stdlib class, I would hope that it would come with its own serialier.

Because ArrayDeque implements MutableList I would expect serializing to just work the same way as MutableList.

I don't want to write my own serializer, or faff around with configuring it.

import kotlinx.serialization.*
import kotlinx.serialization.json.*

fun main() {
    val a = A(
        list = mutableListOf("a", "b", "c"),
        ad = ArrayDeque(mutableListOf("z", "y", "z")),
    )
    println(a)
    println(Json.encodeToString(a))
}

@Serializable
data class A(
    val list: MutableList<String>,
    val ad: ArrayDeque<String>,
)
ERROR: Serializer has not been found for type 'ArrayDeque<String>'. To use context serializer as fallback, explicitly annotate type or property with @Contextual

https://pl.kotl.in/-sBx8yUiQ

Describe the solution you'd like

ArrayDeque is serializable without any extra configuration.

aSemy avatar Jun 25 '25 15:06 aSemy