title: How do I parse nested objects with Retrofit 2?
body: <p>I'm consuming a <code>newsapi</code> whose JSON response is similar to this;</p>
  
  <pre><code>{
  "status": "ok",
  "articles": [
      {
          "source": {
              "id": "bbc-news",
              "name": "BBC News"
          },
          "author": "BBC News",
          "title": "Jubilation greets end of Mugabe era",
          "description": "Zimbabweans celebrate late into the night after Robert Mugabe resigns, ending 37-year rule.",
          "url": "http://www.bbc.co.uk/news/world-africa-42072673",
          "urlToImage": "https://ichef.bbci.co.uk/images/ic/1024x576/p05nt3bn.jpg",
          "publishedAt": "2017-11-22T02:46:09Z"
      },
      {
          "source": {
              "id": "bbc-news",
              "name": "BBC News"
          },
          "author": "BBC News",
          "title": "Dramatic moment N Korea soldier defects",
          "description": "He raced across the border on foot, closely pursued by North Korean troops who shot at him several times.",
          "url": "http://www.bbc.co.uk/news/world-asia-42075986",
          "urlToImage": "https://ichef.bbci.co.uk/news/1024/cpsprodpb/F519/production/_98854726_p05ntph4.jpg",
          "publishedAt": "2017-11-22T04:45:14Z"
      },
      {
        ....
      }
    ]
  }
  </code></pre>
  
  <p>I'm trying to consume that response using Retrofit 2 with GSON.</p>
  
  <p>My POJO Classes are these;</p>
  
  <p><em>NewsList.java</em></p>
  
  <pre><code>public class NewsList {
    public Articles[] articles;
    private String status;
  
    @Override
    public String toString() {
      return "ClassPojo [articles = " + articles + ", status = " + status + "]";
    }
  
    // getters and setters
  }
  </code></pre>
  
  <p><em>Articles.java</em></p>
  
  <pre><code>public class Articles {
    private String publishedAt;
    private String author;
    private String urlToImage;
    private String title;
    private Source source;
    private String description;
    private String url;
  
   // getters and setters
  }
  </code></pre>
  
  <p><em>Source.java</em></p>
  
  <pre><code>public class Source {
    private String id;
    private String name;
  
    // getters and setters
  }
  </code></pre>
  
  <p>My Retrofit Client looks like this;</p>
  
  <pre><code>public interface NewsroomAPI {
    String BASE_URL = "https://newsapi.org/v2/";
  
    @GET("top-headlines")
    Call&lt;NewsList&gt; loadNews(@Query("sources") String source);
  
  }
  </code></pre>
  
  <p>In my <code>MainActivity.java</code> I make calls to the Retrofit client like this;</p>
  
  <pre><code>OkHttpClient okHttpClient = new OkHttpClient().newBuilder().addInterceptor(new Interceptor() {
      @Override public okhttp3.Response intercept(Chain chain) throws IOException {
          Request originalRequest = chain.request();
          Request.Builder builder = originalRequest.newBuilder().header("Authorization",
                  getString(R.string.newsroom_api_key));
          Request newRequest = builder.build();
          return chain.proceed(newRequest);
      }
  }).build();
  
  Retrofit.Builder builder =
              new Retrofit.Builder()
                      .baseUrl(NewsroomAPI.BASE_URL)
                      .addConverterFactory(GsonConverterFactory.create());
  
      Retrofit retrofit = builder.client(okHttpClient).build();
      NewsroomAPI getNewsAPI = retrofit.create(NewsroomAPI.class);
  
      Call&lt;NewsList&gt; call = getNewsAPI.loadNews("bbc-news");
      call.enqueue(new Callback&lt;NewsList&gt;() {
          @Override public void onResponse(Call&lt;NewsList&gt; call, Response&lt;NewsList&gt; response) {
              if (response.isSuccessful()) {
                  NewsList newslist = response.body();
                  Log.w(TAG, "Articles result: " + newslist);
              } else {
                  Toast.makeText(getContext(), "Some error occurred while fetching results!",
                          Toast.LENGTH_SHORT).show();
              }
          }
  
          @Override public void onFailure(Call&lt;NewsList&gt; call, Throwable t) {
              Log.w(TAG, "Failed! ", t);
          }
      });
  </code></pre>
  
  <p>The problem comes when I run the activity and log the results.
  I would expect a log with the <code>status</code> and the returned <code>articles</code>. However, the status is returned successfully, but the <code>articles</code> object is <code>null</code>. The output looks like this;</p>
  
  <pre><code> W/GlobalNewsFragment: Articles result: ClassPojo [articles = null, status = ok]
  </code></pre>
  
  <p>The problem seems to be coming from the way <code>Retrofit2</code> is deserializing the returned JSON object. Is there anything I'm doing wrong?</p>
  
  <p>These are the dependencies in my <em>build.gradle</em> file</p>
  
  <pre><code>compile 'com.squareup.retrofit2:retrofit:2.3.0'
  compile 'com.squareup.retrofit2:converter-gson:2.3.0'
  compile "com.android.support:recyclerview-v7:26.1.0"
  compile "com.squareup.okhttp3:okhttp:3.8.0"
  </code></pre>