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

ResolvableType.getType() should reflect the set up type correctly

    Details

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

      Description

      When creating ResolvableType instances using the factory methods that take generics as arguments (e.g. forClassWithGenerics(…)) I'd expect ResolvableType.getType() to return a ParameterizedType instance. Currently it just returns the raw Class.

      The context I'd like to use this in is RestTemplates ParameterizedTypeReference whose getType() method I override to return a ParameterizedType whose outer type I am aware of but need to customize the component type. Imagine I need to translate an List<Foo> defined as method return type into a Resources<Foo>. I currently create an anonymous class to implement ParameterizedType and manually convert the generics exposed by the manually set up ResolvableType.

      ResolvableType resolvableType = ResolvableType.forClassWithGenerics(ObjectFactory.class, String.class);
      
      Type type = resolvableType.getType();
      
      assertThat(type, is(instanceOf(ParameterizedType.class)));
      assertThat(((ParameterizedType) type).getActualTypeArguments()[0], is(equalTo(String.class)));
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                juergen.hoeller Juergen Hoeller
                Reporter:
                olivergierke Oliver Drotbohm
                Last updater:
                Spring Issuemaster
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Days since last comment:
                  31 weeks, 4 days ago