Search code examples
javaopencsv

How to get the exact name in @CsvBindByName?


When using OpenCSV in order to write csv i'm using the CSVBindByName annotation this way:

    @CsvBindByName(column = "Date")
    private Long date;
    @CsvBindByName(column = "Post content")
    private String text;

But in the generated file the headers are all in UPPERCASE: DATE, POST CONTENT

Is there any way to generate the exact name in the annotation?


Solution

  • Seems that the CsvBindByName annotation always converts the column name to UpperCase based on the OpenCSV source code @ https://sourceforge.net/p/opencsv/source/ci/master/tree/src/main/java/com/opencsv/bean/HeaderColumnNameMappingStrategy.java#l210

    You can try to use custom converter as detailed out here:

    OpenCsv writes wrong column names with BeanToCsv + HeaderColumnNameTranslateMappingStrategy