Querying an existing REST service

In this recipe, from a Spring controller method, we will retrieve data from an existing REST service.

Getting ready

We will query the REST service of the previous Creating a REST service recipe.

We will convert the JSON data received from the REST service to User objects. We will use this User class:

public class User implements {    
  private String name;
  private int age;

  // ... getters and setters
}

How to do it…

Here are the steps for using a REST service:

  1. Add the Maven dependencies for Jackson in pom.xml:
    <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> <version>2.4.2</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> ...

Get Spring Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.