title: Parsing JSON Data with Gson
body: <p>I am a complete beginner when it comes to Http request, json etc. I am trying to access food data through Java's HttpClient and HttpRequest. The data contains alot of information but I am trying only to display the &quot;description&quot;. Here is my Food Class:</p>
  <pre><code>public class Food {
      String description;
  }
  </code></pre>
  <p>and my request:</p>
  <pre><code>public class Test {
      
      public static void main(String[] args) throws IOException, InterruptedException {
          // create a client
          HttpClient client = HttpClient.newHttpClient();
  
          // create a request
          HttpRequest request = HttpRequest.newBuilder()
              .GET()
              .uri(
              URI.create(&quot;https://api.nal.usda.gov/fdc/v1/foods/search?query=mango&amp;pageSize=1&amp;pageNumber=1&amp;api_key=...&quot;)
              ).build();
  
          // use the client to send the request
          HttpResponse&lt;String&gt; response = client.send(request,HttpResponse.BodyHandlers.ofString());
          Food food = new Gson().fromJson(response.body(), Food.class);
          // the response:
          System.out.println(response.body());
          System.out.println(food.description);
      }
  }
  </code></pre>
  <p>Now the first print statement gives me all the data:</p>
  <pre><code>{&quot;totalHits&quot;:11,&quot;currentPage&quot;:1,&quot;totalPages&quot;:11,&quot;pageList&quot;:[1,2,3,4,5,6,7,8,9,10],&quot;foodSearchCriteria&quot;:{&quot;dataType&quot;:[&quot;Survey (FNDDS)&quot;],&quot;query&quot;:&quot;mango&quot;,&quot;generalSearchInput&quot;:&quot;mango&quot;,&quot;pageNumber&quot;:1,&quot;numberOfResultsPerPage&quot;:50,&quot;pageSize&quot;:1,&quot;requireAllWords&quot;:false,&quot;foodTypes&quot;:[&quot;Survey (FNDDS)&quot;]},&quot;foods&quot;:[{&quot;fdcId&quot;:1102670,&quot;description&quot;:&quot;Mango, raw&quot;,&quot;lowercaseDescription&quot;
  </code></pre>
  <p>and this is not even all, but you find the description part at the end of this fraction of all the data. The problem is the second print statement doesn't print the description, it prints null. What goes wrong? The Api documentation: <a href="https://fdc.nal.usda.gov/api-spec/fdc_api.html#/" rel="nofollow noreferrer">https://fdc.nal.usda.gov/api-spec/fdc_api.html#/</a></p>