ClassCastException: RestTemplate returning List instead of List


I have a POJO entity, say org.grassfield.Employee. I expose this as a REST services.

I consume this REST service,

List employeeList = restTemplate.getForObject(
"http://localhost:8080/api/v1/employees" ,

Instead of getting Employee object, I’m getting LinkedHashMap. So my code fails with ClassCastException: RestTemplate returning List<LinkedHashMap> instead of List<Employee>


Jackson uses LinkedHashMap to Serialize/De serialize the entity objects. When I consume the service using parameterized type reference, it works fine.

ResponseEntity<List> response =
"http://localhost:8080/api/v1/employees" ,
new ParameterizedTypeReference<List>(){});
List EmployeeList = response.getBody();


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s