Class CsvToBeanBuilder<T>

java.lang.Object
com.opencsv.bean.CsvToBeanBuilder<T>
Type Parameters:
T - Type of the bean to be populated

public class CsvToBeanBuilder<T> extends Object
This class makes it possible to bypass all the intermediate steps and classes in setting up to read from a CSV source to a list of beans.

This is the place to start if you're reading a CSV source into beans, especially if you're binding the input's columns to the bean's variables using the annotations CsvBindByName, CsvCustomBindByName, CsvBindByPosition, or CsvCustomBindByPosition.

If you want nothing but defaults for the entire import, your code can look as simple as this, where myreader is any valid Reader:
List<MyBean> result = new CsvToBeanBuilder(myreader).withType(MyBean.class).build().parse();

This builder is intelligent enough to guess the mapping strategy according to the following strategy:

  1. If a mapping strategy is explicitly set, it is always used.
  2. If CsvBindByPosition or CsvCustomBindByPosition is present, ColumnPositionMappingStrategy is used.
  3. Otherwise, HeaderColumnNameMappingStrategy is used. This includes the case when CsvBindByName or CsvCustomBindByName are being used. The annotations will automatically be recognized.
Since:
3.9