Skip to content

Add convenient method to construct ParameterizedTypeReference from Type [SPR-16054] #20603

@spring-projects-issues

Description

@spring-projects-issues

Yanming Zhou opened SPR-16054 and commented

I am implementing MethodInterceptor to translate method call to rest api call, so I need translate method.getGenericReturnType() to ParameterizedTypeReference for ResponseEntity, Here is my hack:

new ParameterizedTypeReference<Object>() {
     @Override
     public Type getType() {
          return method.getGenericReturnType();
     }
}

I wish spring provide such as:

public static ParameterizedTypeReference<?> from(Type type){
     return new ParameterizedTypeReference<Object>() {
          @Override
          public Type getType() {
               return type;
          }
     };
}

Backported to: 4.3.12

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions