Using Square Retrofit REST Client with POJO

Another helpful resource when using Retrofit is JSON to POJO or JSON Schema 2 Pojo Tool.

In your maven pom.xml.

<version>(insert latest version)</version>

package com.agilemobiledeveloper.dataradiator.dao;
import retrofit.http.GET;
import retrofit.http.Path;
import retrofit.RestAdapter;
 * @author spannt
public class TestGitHub {
 static final String API_URL = "";
static class GithubUserData{
 String avatar_url;
 String bio;
 String blog;
 String company;
 String created_at;
 String email;
 String events_url;
 Number followers;
 String followers_url;
 Number following;
 String following_url;
 String gists_url;
 String gravatar_id;
 boolean hireable;
 String html_url;
 Number id;
 String location;
 String login;
 String name;
 String organizations_url;
 Number public_gists;
 Number public_repos;
 String received_events_url;
 String repos_url;
 String starred_url;
 String subscriptions_url;
 String type;
 String updated_at;
 String url;
interface GithubUser {
 GithubUserData user(@Path("username") String username);
 * @param args
 public static void main(String... args) {
 // Create a very simple REST adapter which points the GitHub API endpoint.
 RestAdapter restAdapter = new RestAdapter.Builder()

 // Create an instance of our GitHub API interface.
 GithubUser githubUser = restAdapter.create(GithubUser.class);
 GithubUserData userdata = githubUser.user("nxbdi");

 System.out.println("UserData=" + + "," + + "," + +
 userdata.location + "," + userdata.public_repos + "," + userdata.followers);

The library is really simple to use especially if you create your POJO class with the JSONGen.

Console Output:

UserData=Java, Android, NoSQL, SQL. 20 years experience. MS/BS in Com Sci.,,Tim SpannNew Jersey,205,22

Leave a Reply