Class ReflectionCSVProcessor<T>

  • All Implemented Interfaces:
    CSVReader<T>, CSVWriter<T>
    Direct Known Subclasses:
    AdvancedCsvProcessor

    public class ReflectionCSVProcessor<T>
    extends CSVProcessor<T>

    Reflection based implementation for reading/writing CSV files.

    Since:
    2.0
    Author:
    Christoph Praschl
    • Constructor Detail

      • ReflectionCSVProcessor

        public ReflectionCSVProcessor​(char separator,
                                      List<String> columnDefinition,
                                      Class<T> clazz)
        Constructor of a ReflectionCSVProcessor for domain types with simple-typed properties only (int, double, float, long, boolean, char, Integer, Float, Double, Long, String, Character, Boolean)
        Parameters:
        separator - separator used in the csv file
        columnDefinition - columnDefinition of the csv file (can be null for reading if the CSV file contains a header which is used in CSVProcessor.read(File, boolean, boolean))
        clazz - clazz of domain type
    • Method Detail

      • addIgnoredField

        public void addIgnoredField​(String fieldName)
        Add a field which will be ignored so it won't be read or written
        Parameters:
        fieldName - name of the ignored field
      • addFieldConverter

        public void addFieldConverter​(Class<?> clazz,
                                      Function<String,​Object> converter)
        Add a converter for the given class. This converter will be used for converting the CSV string to the expected field type. Using this method you can also override the default converters for simple-typed properties only (int, double, float, long, boolean, char, Integer, Float, Double, Long, String, Character, Boolean)
        Parameters:
        clazz - for which the converter will be used
        converter - converter which transforms the given csv value to an object of the expected type