hi
this is a sample demo using spring boot 3.2.0, kotlin 1.9.20, java 21
data class Person(
val id: Int = 0,
val name: String = ""
)
@SpringBootApplication
@ImportRuntimeHints(MyHintsRegistration::class)
class SpringbootDemoApplication {
@Bean
fun routes() = coRouter {
GET("/") { ok().bodyValueAndAwait("hi") }
GET("/{name}") { ok().bodyValueAndAwait(Person(id = Random.nextInt(), name = it.pathVariable("name")))}
}
}
class MyHintsRegistration : RuntimeHintsRegistrar {
override fun registerHints(hints: RuntimeHints, classLoader: ClassLoader?) {
hints.reflection().registerType<Person>()
}
}
fun main() {
runApplication<SpringbootDemoApplication>()
}
when generated a native graalvm executable and try to call endpoind (curl, httpie, postman) i receive an empty object {} (expect a person serialize object) what wrong here ?
Comment From: bclozel
Registering the type itself just makes it available in the native image for loading the class by its name. Here, the serialization framework will need to look at fields and invoke methods.
This bit is covered in the reference documentation here: https://docs.spring.io/spring-framework/reference/core/aot.html#aot.hints.register-reflection-for-binding
For more questions, please use StackOverflow.
Thanks!