Skip to content

Decode element method always called for optional element when decodeSequentially is used #3080

@rnett

Description

@rnett

Describe the bug

I'm not sure if this is actually a bug or I'm misunderstanding the behavior somehow. The details are here.

To Reproduce

I have a class like this:

@Serializable
data class Foo(val bar: String = "baz")

I'm using it with a custom deserializer that enables sequential decoding. I see decodeStringElement being called for bar which gives me no possibility of handling the missing state of the optional value, i.e. signaling to use the default.

Expected behavior

There is some way to flag that an element is not present and the default should be used.

Environment

  • Kotlin version: 2.2.0
  • Library version: 1.9.0
  • Kotlin platforms: JVM
  • Gradle version: 9.0.0

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