-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unwrap Kotlin inline value classes return values #33026
Comments
Please move that to something we can actually run. It's too bare bone and anything that's missing is a guess on our end. Also, The actual result is pretty useless since we don't have the actual stacktrace that was thrown. |
This looks a regression due to the fact that now all Kotlin function invocations are handled by Kotlin reflection to support various use cases (parameters with default values for example). For some reason, Kotlin reflective invocation via |
After spending some time digging into this issue, I can say it is more nuanced and complex that what I thought originally. As far as I can tell, inline value classes are handled correctly but are interpreted unwrapped since Kotlin reflection handle it that way by design, that's why when you want to treat The use case that is really broken is the serialization by Kotlin Serialization (which is inline value class aware) where there is a mismatch between the Java type of the return value ( I made some try handling the
I will discuss that with the wider team and share the result of the discussion here. |
@serandel The team agreed with my proposal, so I keep that issue in the backlog and create another documentation issue to document current behavior and will work on fixing the Kotlin Serialization use case via #33016. The behavior you hope will likely require #21546 which will take more time to be fixed. |
Hum, based on the additional tests I did, it looks like we still have an inconsistency to fix between |
Awesome work here, @sdeleuze, thanks a lot. I didn't have the time till now, but I take it you already have a better PoC than anything I could extract from my original project, right? Just ping me if I can do anything to help. |
That's ok, I have built a similar repro and I think I have found a way to fix this. |
Affects: Spring 6.1.6
REST controllers are unable to return Kotlin value classes, either directly or wrapped in a ResponseEntity.
I'm using extensively value classes as a way of defining my domain functionally, but have found what I think it's a Spring MVC bug.
Minimal Proof of Concept:
Expected result:
Actual result:
Workaround: just unwrap the inner value at the controller level before returning
What's interesting to me is that I have no problem with value classes as input parameters, either in a RequestBody, a PathVariable, etc. They work seamlessly.
The text was updated successfully, but these errors were encountered: