title: Java Spring rest java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to Cuestionario
body: <p>I have developed the following code using Spring Rest.</p>
  <p>MyProxy</p>
  <pre><code>public Respuesta reject(Integer id,Integer uid, Integer asociation, String reason,Integer type, Cuestionario cuestionario){
      UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(METHOD_REJECT_FULLPATH);
      Map&lt;String,Serializable&gt; map = new HashMap&lt;String,Serializable&gt;(2);
      map.put(&quot;cuestionario&quot;,cuestionario);
      map.put(&quot;motivo&quot;,motivo);
      ResponseEntity&lt;RespuestaServidor&gt; respuesta = restTemplate.exchange(builder.buildAndExpand(id,uid,type, idTipo,asociation).encode().toUri(),
  HttpMethod.POST,
      new HttpEntity&lt;Map&lt;String,Serializable&gt;&gt;(map),
      new ParameterizedTypeReference&lt;Respuesta&gt;(){});
      return respuesta.getBody();
  }
  </code></pre>
  <p>The URI calls this method.</p>
  <pre><code>@RequestMapping(value = Proxy.METHOD_REJECT,method = RequestMethod.POST)
  public @ResponseBody
  ResponseEntity&lt;Respuesta&gt;reject(@PathVariable Integer id,@PathVariable Integer uid,@PathVariable Integer asociation, @PathVariable Integer type,@RequestBody(required=false)Map&lt;String,Object&gt;map){
      final String motivo = (String)map.get(&quot;motivo&quot;);
      final Cuestionario cuestionario = (Cuestionario)map.get(&quot;cuestionario&quot;);        
  </code></pre>
  <p>The problem is in this line</p>
  <pre><code>    final Cuestionario cuestionario = (Cuestionario)map.get(&quot;cuestionario&quot;);        
  </code></pre>
  <p>Given below is the Cuestionario POJO</p>
  <pre><code>public class Cuestionario implements Serializable {
  
     private static final long serialVersionUID = -2669540728368524646L;
     private String respuesta1;
     private String respuesta2;
     private String respuesta3;
     private String respuesta4;
     private boolean fullfilled;
  </code></pre>
  <p>for which I am getting the following exception</p>
  <pre><code>java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.Cuestionario
  </code></pre>
  <p>I have read in other posts similar to this issue which state that it is a kind of Java quirk while other opinions state that a mapper can be used to retreive/cast the Cuestionario object. But I am not aware of any mappers due to my limited expertise on REST.</p>
  <p>I have a very similiar code but with a</p>
  <pre><code>Map&lt;List&lt;Integer&gt;,List&lt;Integer&gt;&gt;
  </code></pre>
  <p>And works perfect. But it is failing for Cuestionario. I have also tried using Spring LinkedMultiValueMap but that doesn't work either.</p>
  <pre><code>MultiValueMap&lt;String,Serializable&gt; map = new LinkedMultiValueMap&lt;String, Serializable&gt;(2);
  map.add(&quot;motivo&quot;,motivo);
  map.add(&quot;cuestionario&quot;,cuestionario);
  </code></pre>
  <p>I need to have to parse the request body somewhere and construct a Cuestionario instance from the data but how can i do that.</p>