Support Kotlin value class properties in SpEL #30468
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
theme: kotlin
An issue related to Kotlin support
type: enhancement
A general enhancement
Milestone
Uh oh!
There was an error while loading. Please reload this page.
It would be great if SpringEL could be improved to support Kotlin Value Classes (probably by unmangling mangled Kotlin names).
I had the following issue.
Class:
It worked everywhere except in Thymeleaf. When I was using it in Thymeleaf, I got an exception:
Turns out, the problem was that the field
id
was of a type that itself is a Kotlin Value Class.What are Kotlin Value Classes?
Kotlin Value Classes are classes that wrap other values, granting more type safety during compilation in Kotlin, without introducing the indirection overhead of a regular class.
Examples:
When value classes are used, the Kotlin compiler mangles the name of the context function to prevent name conflicts when overloading:
The actual signature of the second
updateLocation
function would also beupdateLocation(Double, Double)
, which clashes with the first definition. To prevent that, Kotlin mangles the name into something likeupdateLocation-hash
.This also applies to the getter for properties:
The names for the getters of the properties will be mangled.
To work nicely in Spring, a few pieces are required:
Workaround: Until SpringEL supports Kotlin name mangling, explicitly override the mangled getter name, like this:
The text was updated successfully, but these errors were encountered: