-1

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:

  • String

  • Boolean

  • numeric primitives (Int, Long, etc.)

  • Enum

  • or 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

New contributor
akagami is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • Did you read all migration guides from 2.5 -> 3.5 (so the 2.6, 2.7, 3.0 etc. etc. ones?). You are skipping 8 versions each of them having things to consider while doing the upgrade. Commented Nov 26 at 13:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.