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

RestTemplate is returning LinkedHashMap for Generic Type [SPR-13953] #18526

Closed
spring-projects-issues opened this issue Feb 17, 2016 · 3 comments
Assignees
Labels
in: web status: declined

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Feb 17, 2016

Suresh opened SPR-13953 and commented

I am creating common method which will handle all http methods (GET, POST, PUT) using RestTemplate. The request and response of POJO is marked as generic. Everything is working except GET. GET call is returning LinkedHashMap instead of POJO.

Please take a look at the attached project (File: TestHelloController.java, Lines: 38, 41)


Affects: 4.2.4

Attachments:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 17, 2016

Sébastien Deleuze commented

Suresh I have modified your sample test to make it more consistent, easy to understand, and to see more clearly what occurs (same test results than in your version). Please modify it if this is not exactly what you wanted to demonstrate.

	@Test
	public void testDetailsWithClass() {
		Response<Details> details = template.exchange(url, HttpMethod.GET, null, Response.class, port).getBody();
		assertThat(details.getEntity(), notNullValue());
		assertThat(details.getEntity(), isA(Details.class));
	}

	@Test
	public void testDetailsWithParameterizedTypeReference() {
		Response<Details> details = template.exchange(url, HttpMethod.GET, null, new ParameterizedTypeReference<Response<Details>>() {}, port).getBody();
		assertThat(details.getEntity(), notNullValue());
		assertThat(details.getEntity(), isA(Details.class));
	}

About the behavior observed, indeed testDetailsWithParameterizedTypeReference() is green while testDetailsWithClass() fails because the Class<T> responseType parameter is resolved to Response<Object>, so I think for your use case with generic type you should stick to the ParameterizedTypeReference variant. At this point, I don't think there is something to fix, but please elaborate if you still think there is a bug.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 17, 2016

Suresh commented

Thank you Sebastian. It is tricky to deserialize Response<T>. I will use ParameterizedTypeReference. Thanks for the clarification.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 17, 2016

Sébastien Deleuze commented

You're welcome :-)

@spring-projects-issues spring-projects-issues added type: bug status: declined in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug label Jan 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web status: declined
Projects
None yet
Development

No branches or pull requests

2 participants