I would like to use value class in native image:
@JvmInline
value class MyValueClass(val id: UUID)
I marked it for reflection:
@Configuration(proxyBeanMethods = false)
@RegisterReflectionForBinding(MyValueClass::class, ...)
class BeanConfiguration {
However, when running the image I get:
org.graalvm.nativeimage.MissingReflectionRegistrationError: The program tried to reflectively invoke method public final java.util.UUID com.example.MyValueClass.unbox-impl() without it being registered for runtime reflection. Add it to the reflection metadata to solve this problem. See https://www.graalvm.org/latest/reference-manual/native-image/metadata/#reflection for help.
at org.graalvm.nativeimage.builder/com.oracle.svm.core.reflect.MissingReflectionRegistrationUtils.forQueriedOnlyExecutable(MissingReflectionRegistrationUtils.java:97) ~[na:na]
How I can use inline value classes with GraalVM?
I got it to work in spring boot 3.3 with the following hints (my value class is TimestampMicros
). This makes all members available for reflection, including members generated by the kotlin compiler. It may be possible to fine-tune the included member categories, but I haven't tried:
@SpringBootApplication
@ImportRuntimeHints(PollingApplication.Hints::class)
class PollingApplication {
class Hints : RuntimeHintsRegistrar {
override fun registerHints(hints: RuntimeHints, classLoader: ClassLoader?) {
hints.reflection().registerTypeIfPresent(classLoader, TimestampMicros::class.java.name) {
it.withMembers(*MemberCategory.entries.toTypedArray())
}
}
}
}