title: how to convert LinkedHashMap to Custom java object?
body: <p>I'm trying to get the data from one app to another via RESTful WS and it works, but I cannot use this data since I cannot cast it... WS returns a List of objects like this:</p>
  
  <pre><code>{id=1, forename=John, surname=Bloggs, username=jbloggs, role=Graduate Developer, office=London, skills=[{technology=Java, experience=2.5}, {technology=Web, experience=2.0}, {technology=iOS, experience=0.0}, {technology=.NET, experience=0.0}]}
  </code></pre>
  
  <p>to get I it use Jackson's ObjectMapper:</p>
  
  <pre><code>ObjectMapper mapper = new ObjectMapper();
  
      List&lt;ConsultantDto&gt; list = new ArrayList&lt;ConsultantDto&gt;();
  
  
      try {
  
          list = mapper.readValue(con.getInputStream(), ArrayList.class);
  
      } catch (JsonGenerationException e) {
  
          e.printStackTrace();
  
      } catch (JsonMappingException e) {
  
          e.printStackTrace();
  
      } catch (IOException e) {
  
          e.printStackTrace();
  
      }
  </code></pre>
  
  <p>after that I have 3 lines of code:</p>
  
  <pre><code>System.out.println(list.get(0));
  System.out.println(list.get(0).getForename());
  return list;
  </code></pre>
  
  <p>return because this method's return value is passed to other webservice which displays correct data in a browser. Interesting thing happens with two printing lines, one prints the data from the top of this post ({id:1 ... }) but the other one throws exception:</p>
  
  <pre><code>java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.xxx.xxx.web.dto.rp.ConsultantDto
  </code></pre>
  
  <p>ConsultantDto and SkillDto are two legit classes which have all properties set to match the data from WS, all getters/setters are in place. As far as I'm concerned LinkedHashMap stores stuff as key:value pairs, so I just don't see where is this exception coming from. How can I fix it and why doesn't ObjectMapper just parse the value correctly (which it does when I get a single ConsultantDto rather than a List)?</p>