Skip to content

Add default KSerializer for ArrayDeque #3030

Open
@aSemy

Description

@aSemy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions