title: Create HashMap<String,Map> from List < Map<String,Object>> gives java.lang.ClassCastException
body: <p>Below is my code.Any help is appreciated.
  I am simply not able to read list and create a Map.
  I am passing a <code>List&lt;Map&lt;String, Object&gt;&gt;</code> as a 
  function parameter till the Rest layer.In Rest Proxy call its a
  plain List. In my service layer I need to use Map values stored in the List. </p>
  
  <p>My List has values as mentioned</p>
  
  <pre><code>[{ID=56, VALUE=CPR,DESCRIPTOR=HEAD}, 
  {ID=68,VALUE=RegFinance,DESCRIPTOR=FINANCE}]
  </code></pre>
  
  <p>I want a create <code>Map&lt;String,Map&gt; using List&lt;Map&lt;String, Object&gt;&gt;</code> in below format</p>
  
  <pre><code>{56={ID=56, VALUE=CPR,DESCRIPTOR=HEAD}, 
  68={ID=68,VALUE=RegFinance,DESCRIPTOR=FINANCE}}
  </code></pre>
  
  <p>Below code works before rest call is made i.e in Controller layer but does not work in Service layer after rest call.</p>
  
  <pre><code>    Map&lt;String, Object&gt; userRoleMap = new HashMap&lt;&gt;();
                  for (int count = 0; count &lt; allRolesDetails.size(); count++) {
                      //Map&lt;String, Object&gt; mapp=allRolesDetails.get(count);
                     //Above line Gives Exception
  
                      String[] singleColumn = allRolesDetails.get(count).toString().split(",");
                     //Above line Gives Exception
  
                      for(String pair : singleColumn)  
                      {
                          String[] entry = pair.split("=");   
                          userRoleMap.put(entry[1].trim(),allRolesDetails.get(count)); 
                          break;//add them to the hashmap and trim whitespaces
                      }
                  }
  </code></pre>
  
  <p>Tried all other options on StackoverFlow</p>
  
  <pre><code>Iterator&lt;Map&lt;String, Object&gt;&gt; it = allRolesDetails.iterator();
              while (it.hasNext()) {
                  Map&lt;String, Object&gt; map = it.next(); //so here you don't need a potentially unsafe cast
                  for (Map.Entry&lt;String, Object&gt; entry : map.entrySet()) {
                      System.out.println(entry.getKey() + " = " + entry.getValue());
                  }
              }
  </code></pre>
  
  <p>And</p>
  
  <pre><code>for(Map&lt;String, Object&gt; map:allRolesDetails){
                  for(Map.Entry&lt;String, Object&gt;entry : map.entrySet()){
                      String Key=entry.getKey();
                      Object Value=entry.getValue();
                  }
              }
  </code></pre>
  
  <p>In all the cases I am getting the below exception whenever I am using <code>allRolesDetails.get(count)</code> or trying to user Iterator or Map.Entry.</p>
  
  <p>java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map</p>