-
Notifications
You must be signed in to change notification settings - Fork 652
Open
Description
Describe the bug
When trying to serialize a value class
If the ClassDiscriminatorMode is set to ALL_JSON_OBJECTS
And the value class encapsulates a list
Then it seems like the serializer tries to add a classDiscriminator to a list, resulting in a weird output.
This issue doesn't seem to exist if the value class encapsulates an object or a primitive
To Reproduce
@Serializable
@JvmInline
value class Test(val value: List<Int>)
@OptIn(ExperimentalSerializationApi::class)
val json: Json by lazy {
Json {
classDiscriminatorMode = ClassDiscriminatorMode.ALL_JSON_OBJECTS
}
}
fun main() {
val test = Test(value = listOf(3))
val result = json.encodeToString(test)
println(result) // ["type":"Test",3]
}
Expected behavior
The output should be [3]
Environment
- Kotlin version: 2.1.21
- Library version: 1.8.1
NitroG42 and pdvrieze
Metadata
Metadata
Assignees
Labels
No labels