Skip to content

JsonDecoder: decodeSerializableValuePolymorphic - Include currentTag in cast error #2630

@hfhbd

Description

@hfhbd

What is your use-case and why do you need this feature?
JsonDecodingException: Expected class kotlinx.serialization.json.JsonObject (Kotlin reflection is not available) as the serialized body of F, but had class kotlinx.serialization.json.JsonLiteral (Kotlin reflection is not available)

This error message is not very helpful without the property name, but the name is available: currentTag.

To reproduce:

@Serializable
sealed interface F {
  @Serializable
  @SerialName("a")
  data class A(val f: F): F
}

Json.decodeFromString(F.serializer(), """{"type":"a", "f":"wrong-input"}""")

Describe the solution you'd like
JsonDecodingException: Serial name f expected class kotlinx.serialization.json.JsonObject (Kotlin reflection is not available) as the serialized body of F, but had class kotlinx.serialization.json.JsonLiteral (Kotlin reflection is not available)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions