Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-16054

Add convenient method to construct ParameterizedTypeReference from Type

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Complete
    • Affects Version/s: None
    • Fix Version/s: 4.3.12, 5.0.1
    • Component/s: Core
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      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;
      			}
      		};
      	}
      

        Attachments

          Activity

            People

            • Assignee:
              juergen.hoeller Juergen Hoeller
              Reporter:
              quaff Yanming Zhou
              Last updater:
              Spring Issuemaster
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                26 weeks, 2 days ago