Is there a way to mark a specific class for reflection free serializer generation? #56013
|
Because of similarities, several rest endpoints in a quarkus application I am developing are defined in a generic abstract class. The DTO type is one of the generic type arguments of this abstract class. This causes the discovery for the reflection free serializer generator to not find these DTO classes, which I am not surprised by (due to type erasure of generics). |
Replies: 4 comments 1 reply
|
I ran into the exact same problem with an abstract generic REST base class. The reflection-free serializer feature ( Since the discovery walks the actual annotated resource method as it exists in the bytecode (not the runtime instance), inheriting the endpoint from the generic abstract class without a concrete override never resolves The fix that works without falling back to reflection: override the endpoint method itself in each concrete resource subclass with the resolved return type, even if the body just delegates to public abstract class AbstractResource<T> {
@GET
public T get() {
return doGet();
}
protected abstract T doGet();
}
@Path("/widgets")
public class WidgetResource extends AbstractResource<WidgetDto> {
@GET // re-declare with a concrete return type so it gets indexed correctly
@Override
public WidgetDto get() {
return super.get();
}
// ...
}Once |
|
The pull request linked above (already merged on main) should solve improve the type discovery and trigger the generation of the Jackson serializer also for the situation explicitly reported here #56013 (reply in thread) As I wrote in the comment to that pull request, for now I'm not adding any mechanism to explicitly mark a specific class for reflection free serializer generation because I'd like that the discovery could be as automatic as possible. I will eventually add it only if and when we will find that there is a situation where it is impossible to automatically infer it. For this reason I'm closing this discussion for now, but feel free to reopen it (or to send a proper bug report) if you can find any other situation where a reflection-free Jackson serializer should be generated but it's missing. |
See #56238