To Reproduce
@Serializable
data object Foo {
@EncodeDefault
val bar: String = "value"
}
@Test
fun testFoo() {
val json = Json.encodeToString(Foo)
assertEquals("""{"bar":"value"}""", json) // failed, result is {}
}
Expected behavior
All properties annotated with @EncodeDefault must be present in the json, just as they are in the data classes:
@Serializable
data class FooDataClass(val bar1: String) {
@EncodeDefault
val bar2: String = "value2"
}
@Test
fun testFooDataClass() {
val json = Json.encodeToString(FooDataClass("value1"))
assertEquals("""{"bar1":"value1","bar2":"value2"}""", json) // passed
}
Environment
- Kotlin version: 2.3.10
- Library version: 1.11.0
- Kotlin platforms: JVM
- Gradle version: 9.6.0
To Reproduce
Expected behavior
All properties annotated with
@EncodeDefaultmust be present in the json, just as they are in the data classes:Environment