Skip to content
robert-bor edited this page Mar 3, 2013 · 28 revisions

CSVeed currently has the following annotations:

  • CsvFile; generic instructions for parsing the CSV file and converting to Rows and Beans
  • CsvCell; custom instructions for properties, allowing mappings to column index or names and whether value is required
  • CsvIgnore; orders CSVeed to ignore a property
  • CsvDate; allows a custom date format to be applied to a property
  • CsvConverter; set a custom PropertyEditor to be applied to a property

#CsvFile Contains the generic instructions for parsing the CSV file and converting to Rows and Beans. The following settings are supported by CsvFile:

  • parse instructions; escape, quote, separator, end-of-line and comment -- this determines what your CSV file looks like
  • use header; whether the CSV file contains a header and must be read as such
  • start row; the line from where to start reading the CSV file, zero-based
  • skip lines; both empty and comment lines and whether they must be ignored or parse must be attempted
  • mapping strategy; by default this will be ColumnIndexMapping, which maps to Bean properties on the basis of the column index. Alternatively, this could be ColumnNameMapping, which maps to Bean properties on the basis of the name of the column (ie, the header name).

Assume the following CSV:

    first name, surname, street, city, trademark
    % First a line on mr Hawking
    'Stephen', 'Hawking', '110th Avenue', 'New York', 'History of the \\'Universe\\''
    % Then on mr Einstein
    'Albert', 'Einstein', 'Leipzigerstrasse', 'Berlin', '\\'E=mc2\\''

The Bean header can be annotated as follows:

    @CsvFile(comment = '%', quote='\\'', escape='\\\\', separator=',', skipCommentLines = true)
    public class Bean {

#CsvCell

#CsvIgnore

#CsvDate

#CsvConverter