Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jaxrs generic return type is abstract class. #3082

Closed
andrejpetras opened this issue Jan 23, 2019 · 2 comments
Closed

jaxrs generic return type is abstract class. #3082

andrejpetras opened this issue Jan 23, 2019 · 2 comments

Comments

@andrejpetras
Copy link
Contributor

Hi,
I get always the abstract (super) type and not the generic type in the response definition for my jaxrs service.
Java code example

@Stateless
@Path("token")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public class ProcessTokenRestService extends AbstractEntityRestService<ProcessTokenDTO> {
}

public abstract class AbstractEntityRestService<DTO extends PersistentDTO> implements EntityRestService<DTO> {

    public DTO create(DTO object) throws Exception {
        return null;
    }

}

Part of the openapi.json

  "paths" : {
    "/token" : {
      "post" : {
        "operationId" : "create",
        "requestBody" : {
          "content" : {
            "application/json" : {
              "schema" : {
                "$ref" : "#/components/schemas/ProcessTokenDTO"
              }
            }
          }
        },
        "responses" : {
          "default" : {
            "description" : "default response",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/PersistentDTO"
                }
              }
            }
          }
        }
      }
    }
  },

I would like to have this for the response.

        "responses" : {
          "default" : {
            "description" : "default response",
            "content" : {
              "application/json" : {
                "schema" : {
                  "$ref" : "#/components/schemas/ProcessTokenDTO"
                }
              }
            }
          }
        }
      }

The response type should be ProcessTokenDTO (as input parameter) and not PersistentDTO.
I use the test1.zip project to reproduce this issue. How to reproduce: mvn clean install

Thanks
Andrej

test1.zip

@andrejpetras
Copy link
Contributor Author

I check the Reader class in the jaxrs module. The parameter types are taken from the AnnotatedMethod object. For the return type, the type from the java method is used.
I create simple fix and a pull request.

Could you please look at it if it is ok or create another solution for this issue.

Thanks
Andrej

frantuma added a commit that referenced this issue Jan 30, 2019
frantuma added a commit that referenced this issue Jan 30, 2019
frantuma added a commit that referenced this issue Jan 30, 2019
 ref #3082 - updated returnType handling
@frantuma
Copy link
Member

Thanks! merged #3096 (includes #3083)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants