title: Java: Create CSV from Get Array with Object
body: <p>I have </p>
  
  <pre><code>data= [{
            id=1, 
            employee_name=Tiger Nixon, 
            employee_salary=320800, 
            employee_age=61, 
            profile_image=
         }, 
         {
            id=2, 
            employee_name=Garrett Winters, 
            employee_salary=170750, 
            employee_age=63, 
            profile_image=
         }, 
         {
            id=3, 
            employee_name=Ashton Cox, 
            employee_salary=86000, 
            employee_age=66, 
            profile_image=
         }, 
         {
            id=4, 
            employee_name=Cedric Kelly, 
            employee_salary=433060, 
            employee_age=22, 
            profile_image=
         }
        ]
  </code></pre>
  
  <p>I have employee class</p>
  
  <pre><code>public class Employee {
      private String employee_name;
      private String employee_salary;
      private String employee_age;
      private String id;
      private String profile_image;
  
      public String toCsvRow() {
          String csvRow = "";
          for (String value : Arrays.asList(employee_name,employee_salary,employee_age)) {
              String processed = value;
              if (value.contains("\"") || value.contains(",")) {
                  processed = "\"" + value.replaceAll("\"", "\"\"") + "\"";
              }
              csvRow += "," + processed;
          }
          return csvRow.substring(1);
      }
  
      public String getEmployee_name() {
          return employee_name;
      }
  
      public String getEmployee_salary() {
          return employee_salary;
      }
  
      public String getEmployee_age() {
          return employee_age;
      }          
  }
  </code></pre>
  
  <p>I tried for</p>
  
  <pre><code>Map&lt;String, ArrayList&lt;Employee&gt;&gt; map = mapper.readValue(url, Map.class);
  ArrayList&lt;Employee&gt; emps = map.get("data");
  emps.get(0).toCsvRow()
  
  Exception in thread "main" java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to org.example.model.Employee
  </code></pre>
  
  <p>Now I cannot call toCSVRow using emps.</p>