title: Writing generic POJO to CSV transformer
body: <p>My use case was to write a generic CSV transformer, which should be able to convert any Java POJO to CSV string. </p>
  
  <p>My Implementation : </p>
  
  <pre><code>public &lt;T&gt; List&lt;String&gt; convertToString(List&lt;T&gt; objectList) {
  
          List&lt;String&gt; stringList = new ArrayList&lt;&gt;();
          char delimiter = ',';
          char quote = '"';
          String lineSep = "\n";
  
          CsvMapper mapper = new CsvMapper();
          CsvSchema schema = mapper.schemaFor(!HOW_TO!);
  
          for (T object : objectList) {
  
              try {
                  String csv = mapper.writer(schema
                          .withColumnSeparator(delimiter)
                          .withQuoteChar(quote)
                          .withLineSeparator(lineSep)).writeValueAsString(object);
  
              } catch (JsonProcessingException e) {
  
                  System.out.println(e);
              }
          }
  
          return stringList;
  }
  </code></pre>
  
  <p>I was using Jackson-dataformat-csv library, but I'm stuck with !HOW_TO! part, ie How to extract the .class of the object from the objectList. I was studying and came across Type Erasure, So I think it is somehow not possible other than giving the .class as parameter to my function. But I'm also extracting this object list from generic entity using Java Reflection, so I can't have the option to provide the .class params. </p>
  
  <p>Is there a workaround for this? </p>
  
  <p>OR </p>
  
  <p>Any other approaches/libraries where I can convert a generic <code>List&lt;T&gt; objectList to List&lt;String&gt; csvList</code> with functionality of adding delimiters, quote characters, line separators etc. </p>
  
  <p>Thanks!</p>