How to declaratively register classes for reflection in Spring Native?

55 Views Asked by At

Using Spring Boot 3.2.1, I want to use Spring Native.

Spring goes as far as possible to add reflection information on all the objects that it can detect are used by Jackson, e.g. inspecting the signatures of the controllers.

I'm using OpenAPI generator to generate a library of my business objects. There is polymorphism involved, so Spring cannot lookup all the classes by inspecting the controllers' signatures.

I'd like to be able to register all these generated classes at once for reflection. Classes are bundled in a library, and used in many Spring Boot apps, so having a solution that is defined once for all in the library is what I'm looking for.

using @RegisterReflectionForBinding doesn't solve the problem, as all the classes need to be listed explicitly, so it becomes a very tedious thing to maintain with generated code.

I'd be glad if I could: a) annotate my generated classes with something similar in behavior as Micronaut's @ReflectiveAccess or Quarkus' @RegisterForReflection. That's easy to do with OpenAPI Generator b) define once the lookup using package name, in something like a configuration class

From the comments on https://github.com/spring-projects/spring-framework/issues/29194, I understand that a) is not currently possible. Are there available paths for b) ?

0

There are 0 best solutions below