eclipse-ee4j / eclipse-ee4j/jersey
MP rest client cannot use generic interfaces
- Dominant language
- Java
- Stars
- 730
- Forks
- 382
- PR merge metrics
- No merged PRs in 30d
Description
Having an interface
```
interface ViewResource {
@GET
@Path("{id}")
@Produces(APPLICATION_JSON)
V get(@PathParam("id") UUID id);
}
```
... then defining
```
@Path("employee")
interface EmployeeResource extends ViewResource {
}
```
... I try to use the interface `EmployeeResource` as a MP rest client. Building the client fails with the following exception
```
Exception in thread "main" java.lang.IllegalArgumentException: Type parameter V not a class or parameterized type whose raw type is a class
at javax.ws.rs.core.GenericType.getClass(GenericType.java:179)
at javax.ws.rs.core.GenericType.(GenericType.java:136)
at org.glassfish.jersey.microprofile.restclient.MethodModel$Builder.returnType(MethodModel.java:561)
at org.glassfish.jersey.microprofile.restclient.MethodModel$Builder.build(MethodModel.java:631)
at org.glassfish.jersey.microprofile.restclient.MethodModel.from(MethodModel.java:107)
at org.glassfish.jersey.microprofile.restclient.RestClientModel.parseMethodModels(RestClientModel.java:113)
at org.glassfish.jersey.microprofile.restclient.RestClientModel.from(RestClientModel.java:70)
at org.glassfish.jersey.microprofile.restclient.RestClientBuilderImpl.build(RestClientBuilderImpl.java:195)
```
Jersey Server is able to use this generic approach (i.e. implement a generic `ViewResourceBase` then a `EmploymentResourceImpl`.
Also the MP rest client from `RestEasy` simply works.
See [this project](https://github.com/pa314159/jersey-mp-generic) that demonstrates the issue. I also have a fix on [this branch](https://github.com/pa314159/jersey/tree/generic-return-type) that uses `geantyref`.
Let me know if you want to create a PR based on it or if you want an independent fix.
Contributor guide
Research direction
Start with the linked demonstration project and trace the failure through org.glassfish.jersey.microprofile.restclient.MethodModel.Builder.returnType, RestClientModel, and RestClientBuilderImpl. Compare the proposed generic-return-type branch and verify that an EmployeeResource extending ViewResource can build and invoke the MP REST client without the GenericType exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100