title: The elements of collections of a deserialized JSON object are LinkedHashMap
body: <p>I am sending a request to the controller <a href="https://pastebin.com/d4SHZuZh" rel="nofollow noreferrer">https://pastebin.com/d4SHZuZh</a>. JSON deserialize using Builder from this class. <code>@JsonDeserialize(builder = ContributionNewRequest.Builder.class)</code></p>
  
  <p>The elements of the collection are <code>? extends MovieInfoDTO</code> objects inheriting from <code>MovieInfoDTO</code>.</p>
  
  <p>when getting items from e.g. list <code>elementsToAdd</code></p>
  
  <pre><code>contribution.getElementsToAdd()
              .forEach(boxOffice -&gt; {
                  ...
              });
  </code></pre>
  
  <p>it turns out that the <code>boxOffice</code> element is a <code>java.util.LinkedHashMap</code> object.</p>
  
  <p>I found a mention on the internet on the Internet <a href="http://www.baeldung.com/jackson-collection-array" rel="nofollow noreferrer">http://www.baeldung.com/jackson-collection-array</a> that JSON default sets the elements of the collection as <code>LinkedHashMap</code>.</p>
  
  <p>What do I need to do to make the objects of the correct type?</p>
  
  <pre><code>java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.jonki.popcorn.common.dto.movie.BoxOffice
  at java.util.ArrayList.forEach(ArrayList.java:1257) ~[na:1.8.0_171]
  </code></pre>