title: Parsing nested json received from an api to objects in spring boot
body: <p>I am creating a spring boot application which receives some JSON data from a 3rd party api. The JSON data has so many nested objects.I want to map them as Java objects. Below is the code I wrote for getting the api response.</p>
  <pre><code>public ResponseEntity&lt;MovieSearchResultsDto&gt; getMovies(String searchText, String countryCode) {
          
          logger.info(&quot;GetMovies Service started&quot;);
          String url = prepareUrl(searchText,countryCode);
          HttpHeaders header = new HttpHeaders();
          prepareHeader(header);
          HttpEntity&lt;String&gt; requestEntity = new HttpEntity&lt;String&gt;(header);
          try {
              logger.info(&quot;Calling the API for movie info&quot;);
              responseEntity = restClient.exchange(url,
                      HttpMethod.GET,
                      requestEntity,
                      MovieSearchResultsDto.class);
          }catch (Exception e) {
              logger.error(&quot;Exception occured while calling the API &quot;+ e);
              if(responseEntity.getStatusCodeValue() != 200) {
  
              }
          }
          logger.info(&quot;GetMovies Service Ended&quot;);
          return responseEntity;
          
      }
  </code></pre>
  <p>And the JSON response looks like</p>
  <pre><code>{
      &quot;results&quot;: [
          {
              &quot;id&quot;: ******,
              &quot;picture&quot;: &quot;url&quot;,
              &quot;name&quot;: &quot;Titanic&quot;,
              &quot;locations&quot;: [
                  {
                      &quot;icon&quot;: &quot;url&quot;,
                      &quot;display_name&quot;: &quot;Amazon Instant Video&quot;,
                      &quot;name&quot;: &quot;AmazonInstantVideoIVAGB&quot;,
                      &quot;id&quot;: &quot;***&quot;,
                      &quot;url&quot;: &quot;url&quot;
                  }
              ],
              &quot;provider&quot;: &quot;iva&quot;,
              &quot;weight&quot;: 0,
              &quot;external_ids&quot;: {
                  &quot;iva_rating&quot;: null,
                  &quot;imdb&quot;: {
                      &quot;url&quot;: &quot;url&quot;,
                      &quot;id&quot;: &quot;tt0046435&quot;
                  },
                  &quot;tmdb&quot;: {
                      &quot;url&quot;: &quot;url&quot;,
                      &quot;id&quot;: &quot;id&quot;
                  },
                  &quot;wiki_data&quot;: {
                      &quot;url&quot;: &quot;url&quot;,
                      &quot;id&quot;: &quot;id&quot;
                  },
                  &quot;iva&quot;: null,
                  &quot;gracenote&quot;: null,
                  &quot;rotten_tomatoes&quot;: null,
                  &quot;facebook&quot;: null
              }
          }
     ]  }
  </code></pre>
  <p>What I have done is , I created a class <strong>MovieSearchResultsDto</strong> and include a list as its data member with getters and setters.</p>
  <pre><code>private List&lt;MoviesDto&gt; results = new ArrayList&lt;&gt;();
  </code></pre>
  <p>And created <strong>MoviesDto</strong> class as below</p>
  <pre><code>public class MoviesDto {
  
      private String id;
      private String name;
      private String picture;
      @JsonInclude(value = Include.NON_EMPTY)
      private List&lt;MovieLocation&gt; locations = new ArrayList&lt;MovieLocation&gt;();
      @JsonInclude(value = Include.NON_EMPTY)
      private List&lt;ExternalIds&gt; external_ids = new ArrayList&lt;ExternalIds&gt;();
      
      public MoviesDto() {
          
      }
      
      //getters and setters
      
  }
  
  class MovieLocation{
      private String icon;
      private String id;
      private String display_name;
      private String name;
      private String url;
      
      public MovieLocation() {
          
      }
      //getters and setters
  }
  
  class ExternalIds{
      
      private IdAndUrl imdb;
      private IdAndUrl tmdb;
      private IdAndUrl wiki_data;
  
      public ExternalIds() {
          
      }
      //getters and setters
  
      
  }
  
  class IdAndUrl{
      private String url;
      private String id;  
      public IdAndUrl() {
          
      }
      //getters and setters
  }
  </code></pre>
  <p>But it shows error while parsing.</p>
  <pre><code>Exception occured while calling the API org.springframework.web.client.RestClientException: Error while extracting response for type [class com.prebeesh1427.MovieNameServiceProvider.dto.MovieSearchResultsDto] and content type [application/json]; nested exception is org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.util.ArrayList&lt;com.prebeesh1427.MovieNameServiceProvider.dto.ExternalIds&gt;` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.util.ArrayList&lt;com.prebeesh1427.MovieNameServiceProvider.dto.ExternalIds&gt;` out of START_OBJECT token
   at [Source: (PushbackInputStream); line: 1, column: 1054] (through reference chain: com.prebeesh1427.MovieNameServiceProvider.dto.MovieSearchResultsDto[&quot;results&quot;]-&gt;java.util.ArrayList[0]-&gt;com.prebeesh1427.MovieNameServiceProvider.dto.MoviesDto[&quot;external_ids&quot;])
  </code></pre>
  <p>I am a newbie to this area. Kindly help me not just only to resolve this issue but to understand the concept of these parsing techniques too.</p>
  <p>Thanks in advance</p>