1

I am using OpenCSV BeanToCsv to dump a list of beans to a csv file. Everything is working however it creates the column names from the field names in the bean I am using. How do I change the column names that get created in the csv?

Example Column Mapping:

String[] columns = new String[] { "projectId", "patientFirstName", "patientLastName"};

//But I actually want the column for projectId to be "PROJECT_ID" in the
//.csv file and patientFirstName to be "PATIENT_FIRST_NAME".

There has to be some obvious easy way to do this but I just don't see it. How do I accomplish this?

DevErik
  • 11
  • 2
  • 1
    Does [OpenCsv writes wrong column names with BeanToCsv + HeaderColumnNameTranslateMappingStrategy](http://stackoverflow.com/questions/33778223/opencsv-writes-wrong-column-names-with-beantocsv-headercolumnnametranslatemapp) help? – K.Nicholas Apr 03 '16 at 21:02
  • Not that I can tell. – DevErik Apr 04 '16 at 02:54
  • Are you sure? The link references a class that "Expands on HeaderColumnNameMappingStrategy by allowing the user to pass in a map of column names to bean names. This way the fields in the bean do not have to match the fields in the csv file." – K.Nicholas Apr 04 '16 at 04:36
  • Ok, seems a little hackish but I have it going. Really surprised if there isn't an out of the box way of doing this. – DevErik Apr 04 '16 at 22:00
  • Sounds good. Want to post some example code? – K.Nicholas Apr 04 '16 at 22:07

0 Answers0