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:
- 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> <version>2.4.2</version> </dependency> 
- In a controller method, define the URL of the REST service to query...
 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                