Support properties in kotlinx.serialization codecs

This commit adds support for Kotlin properties in Spring WebFlux
controllers, supported for reasons explained in gh-31856, with
kotlinx.serialization codecs.

See gh-34284
This commit is contained in:
Sébastien Deleuze
2025-01-27 14:48:58 +01:00
parent 683733a682
commit a970fc16aa
2 changed files with 30 additions and 15 deletions

View File

@@ -145,10 +145,24 @@ class KotlinSerializationJsonEncoderTests : AbstractEncoderTests<KotlinSerializa
assertThat(encoder.canEncode(ResolvableType.forClass(BigDecimal::class.java), null)).isFalse()
}
@Test
fun encodeProperty() {
val input = Mono.just(value)
val method = this::class.java.getDeclaredMethod("getValue")
val methodParameter = MethodParameter.forExecutable(method, -1)
testEncode(input, ResolvableType.forMethodParameter(methodParameter), null, null) {
it.consumeNextWith(expectString("42"))
.verifyComplete()
}
}
@Serializable
data class Pojo(val foo: String, val bar: String, val pojo: Pojo? = null)
fun handleMapWithNullable(map: Map<String, String?>) = map
val value: Int
get() = 42
}