I'm migrating a Kotlin + Spring WebFlux application from Spring Boot 2.5.x to Spring Boot 3.5.x, and several controller endpoints that used to work now consistently fail with ClassCastException.
🔍 What breaks
Any endpoint that returns a wrapped response of type:
StringBooleannumeric primitives (
Int,Long, etc.)Enumor lists of these (e.g.
List<Enum>)
throws exceptions such as:
ClassCastException: APIResponse$Success cannot be cast to CharSequence
ClassCastException: APIResponse$Success cannot be cast to java.lang.Boolean
ClassCastException: APIResponse$Success cannot be cast to java.lang.Enum
đź”§ How we wrap responses
We use a generic wrapper for all controller responses:
val result = block()
APIResponse.Success(result)
Success is defined as:
class Success<T>(
private val response: T,
val status: HttpStatus = HttpStatus.OK
) : APIResponse<T>(status) {
@JsonValue
fun value() = response
}
@JsonValue is used so the client receives the raw value T (e.g. "string" instead of { response: "string" }).
What changed after upgrading
This worked fine in Spring Boot 2.5.x
After upgrading to Spring Boot 3 / Spring Framework 6, only scalar or enum types fail