title: Gson - ignore json fields when parsing JSON to Object
body: <p>There is a question <a href="https://stackoverflow.com/questions/5635226/gson-ignore-json-field-and-deserialize">here</a> that is similar to my question but not exactly what I'm looking for.</p>
  
  <p>I've a JSON response  from a webservice, let's say <a href="http://maps.googleapis.com/maps/api/directions/json?origin=Toronto&amp;destination=Montreal&amp;sensor=false" rel="nofollow noreferrer">this JSON response</a>: </p>
  
  <pre><code>{
     "routes" : [
        {
           "bounds" : {
              "northeast" : {
                 "lat" : 45.5017123,
                 "lng" : -73.5672184
              },
              "southwest" : {
                 "lat" : 43.6533103,
                 "lng" : -79.3827675
              }
           },
           "copyrights" : "Dados do mapa ©2015 Google",
           "legs" : [
              {
                 "distance" : {
                    "text" : "541 km",
                    "value" : 540536
                 },
                 "duration" : {
                    "text" : "5 horas 18 min.",
                    "value" : 19058
                 },
                 "end_address" : "Montreal, QC, Canada",
                 "end_location" : {
                    "lat" : 45.5017123,
                    "lng" : -73.5672184
                 },
                 "start_address" : "Toronto, ON, Canada",
                 "start_location" : {
                    "lat" : 43.6533103,
                    "lng" : -79.3827675
                 }, 
                 (...)
  </code></pre>
  
  <p>In this JSON I' just interested on the <code>distance</code> object. My question is, how can I ignore all the other fields?</p>
  
  <p>I tried to build my object starting from <code>legs</code>, as it is the first non repetitive object name from <code>distance</code> to the root.</p>
  
  <p>Here's my object:</p>
  
  <pre><code>public class MyObject {
  
      public ArrayList&lt;Distance&gt; legs;
  
      public static class Distance {
          public String text;
          public String value;
      }
  }
  </code></pre>
  
  <p>but the <code>ArrayList legs</code> is always <code>null</code>.</p>
  
  <p>How can I accomplish this? Ignore fields to the left from the pretended json field.</p>