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

ResolvableType.getType() should reflect the set up type correctly [SPR-12701] #17298

Closed
spring-issuemaster opened this issue Feb 8, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Feb 8, 2015

Oliver Drotbohm opened SPR-12701 and commented

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

Issue Links:

  • #18116 OutOfMemory Exception when publishing User Events
  • #21001 Resolvable type cannot resolve generic between different collection types

Referenced from: commits 91a0107

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 9, 2015

Juergen Hoeller commented

Since we're not synthesizing a ParameterizedType at all yet, it isn't quite intuitive for Resolvable.getType to return such a non-provided ParameterizedType reference. I'd rather suggest a dedicated ResolvableType.getParameterizedType method, building such a synthetic type handle on demand.

Providing programmatically assembled generics metadata is a recurring topic in 4.2, so this fits in there nicely. Since your present workaround is just doing what such a new ResolvableType method would be doing, there is no strong need to have it in 4.1.x right away, right? Would you be ok with having it in 4.2 only, as part of a wider revision?

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 9, 2015

Oliver Drotbohm commented

I'm not sure about the additional method. What would it return if you just set up a ResolvableType from a plain Class. I thought getType() was the right thing to call, as Type basically allows to abstract over all the possible generic situations. I don't even care that the method returns a ParameterizedType, IMO it just needs to reflect what I've set up in the first place. Exposing a method returning a Type is basically creating the expectation to be able to get everything but a Class and the only way to create such a scenario is using the forClassWithGenerics(…) methods.

4.2 would certainly work as well but basically imply that we're not gonna be able to remove our workaround until Spring Data can move to that version, which is usually when the next Spring version is coming out. A back-port to 4.1.x would allow us to move to that code once 4.2 has been released.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 20, 2015

Juergen Hoeller commented

Alright, implemented for getType() itself now, as originally suggested.

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.