title: in a spring mvc controller access arraylist element where the contains of the arraylist is class objects
body: <p>Doing this Project in Spring MVC
  My MVC controller</p>
  
  <pre><code>@Controller
  public class HomeController {
  @RequestMapping(value = "/cars", method = RequestMethod.POST)
  public @ResponseBody ArrayList&lt;Car&gt; update(@RequestBody ArrayList&lt;Car&gt; cars) {
  System.out.println(cars.get(0)); 
  
  /* How can I get the color separately for the cars.get(0) and cars.get(0) */    
  
  
      return (cars);
  }
  
  }
  </code></pre>
  
  <p>My car.java POJO</p>
  
  <pre><code>package com.rev.retpostjson;
  
  public class Car {
  
  private String VIN;
  private String color;
  private Integer miles;
  
  public String getVIN() {
      return VIN;
  }
  public void setVIN(String vIN) {
      VIN = vIN;
  }
  public String getColor() {
      return color;
  }
  public void setColor(String color) {
      this.color = color;
  }
  public Integer getMiles() {
      return miles;
  }
  public void setMiles(Integer miles) {
      this.miles = miles;
  }
  
  }
  </code></pre>
  
  <p>My input JSON</p>
  
  <pre><code>[
  
  
   {
  "color":"Blue",
  "miles":200,
  "vin":"1234"
  
  
   },
  
  
   {
  "color":"Red",
  "miles":500,
  "vin":"1235"
  
  
   }
  ]
  </code></pre>
  
  <p>My output JSON</p>
  
  <pre><code>[
  
  
  {
  "color": "Blue",
  "miles": 200,
  "vin": "1234"
  
  
   },
  
  
   {
  "color": "Red",
  "miles": 500,
  "vin": "1235"
  
  
  
  }
  ]
  </code></pre>
  
  <p>The <code>System.out.println(cars.get(0));</code> inside the controller displays <code>{color=Blue, miles=200, vin=1234}</code> in the console.  I want to use the value of the color separately i.e. the color of the <code>cars.get(0)</code> and <code>cars.get(1)</code> so that I can write some logic depending on that color. I tried those things <code>String f=cars.get(0).toString();</code> <code>String f=cars.get(0);</code>   <code>Car f=cars.get(0);System.out.println(f.getColor());</code> and <code>cars.get(0).getColor()</code><br>
  But every time I found error like following </p>
  
  <pre><code>[Request processing failed; nested exception is java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.rev.retpostjson.Car] with root cause
  java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to com.rev.retpostjson.Car
  </code></pre>
  
  <p>I have not been able to understand where I am wrong.How to achieve the desired goal.</p>