Due to #20606, we had to introduce KotlinBodySpec
in Spring Framework 5.0.x in order to unlock Kotlin developers for most common use cases of WebTestClient
in Kotlin.
As of Kotlin 1.6, the related Kotlin issue on recursive generic types has been fixed, making it possible for Spring Framework to provide regular reified extensions for ResponseSpec
methods that takes a ParameterizedTypeReference
(to be verified of course, but that's my current understanding).
As a consequence, my proposal is in Spring Framework 6 to remove KotlinBodySpec
, as well as the current inline fun <reified B : Any> ResponseSpec.expectBody(): KotlinBodySpec<B>
extension, and introduce regular reified extensions for ResponseSpec.expectBody
since ResponseSpec.expectBodyList
, ResponseSpec.returnResult
extensions already exists.
This is a breaking change, I am afraid impossible to avoid, so it should be mentioned in the release notes. I am not sure we should deprecate the related extension in Spring Framework 5.3 since we need to support Kotlin 1.5 there and the current extension prevent to introduce the new proper one describe in this issue.
Comment From: sdeleuze
See related comment in KT-5464 where we discussed the fact that while this is now usable with Kotlin 1.6+, Kotlin is still more verbose than Java so there is room for improvement.