Skip to content

Support Kotlin value (JvmInline) classes as suspend handler method arguments #27345

@efemoney

Description

@efemoney

Affects: Spring Framework 5.3.9, Spring Boot 2.5.4


Using a @JvmInline value class as a handler method argument fails with the following:

java.lang.IllegalArgumentException: object is not an instance of declaring class

My best guess is this happens because, say with the example below:

@JvmInline value class ProductId(val id: String)

@GetMapping("/product")
suspend fun getProduct(@RequestParam productId: ProductId) { ... }

at runtime the getProduct parameter type when viewed from Java reflection is the wrapped value type (String) but when viewed from Kotlin reflection, the parameter is the wrapper value class (ProductId). The error is thrown when the function is invoked from kotlin reflection with String instance arguments (contributed by the RequestParam resolver) but the kotlin reflection API expects the ProductId instance (which it automatically unboxes, exception is thrown here)

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)status: duplicateA duplicate of another issuetheme: kotlinAn issue related to Kotlin support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions