T
- Type of the bean to be populatedpublic class CsvToBeanBuilder<T> extends Object
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
, CsvCustomBindByPosition
, or CsvBind
.
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:
CsvBindByPosition
or CsvCustomBindByPosition
is present,
ColumnPositionMappingStrategy
is used.HeaderColumnNameMappingStrategy
is used. This includes
the case when CsvBindByName
, CsvCustomBindByName
, or
CsvBind
are being used. The annotations will automatically be
recognized.Constructor and Description |
---|
CsvToBeanBuilder(Reader reader)
Constructor with the one parameter that is most definitely mandatory, and
always will be.
|
public CsvToBeanBuilder(Reader reader)
reader
- The reader that is the source of data for the CSV importpublic CsvToBean build() throws IllegalStateException
CsvToBean
out of the provided information.CsvToBean
IllegalStateException
- If a necesary parameter was not specified.
Currently this means that both the mapping strategy and the bean type
are not set, so it is impossible to determine a mapping strategy.public CsvToBeanBuilder withMappingStrategy(MappingStrategy<T> mappingStrategy)
mappingStrategy
- Silence Javadoc warningsCsvToBean.setMappingStrategy(com.opencsv.bean.MappingStrategy)
public CsvToBeanBuilder withFilter(CsvToBeanFilter filter)
filter
- Silence Javadoc warningsCsvToBean.setFilter(com.opencsv.bean.CsvToBeanFilter)
public CsvToBeanBuilder withThrowExceptions(boolean throwExceptions)
throwExceptions
- Silence Javadoc warningsCsvToBean.setThrowExceptions(boolean)
public CsvToBeanBuilder withFieldAsNull(CSVReaderNullFieldIndicator indicator)
indicator
- Silence Javadoc warningsCSVParser.CSVParser(char, char, char, boolean, boolean, boolean, CSVReaderNullFieldIndicator)
public CsvToBeanBuilder withKeepCarriageReturn(boolean keepCR)
keepCR
- Silence Javadoc warningsCSVReader.CSVReader(java.io.Reader, char, char, char, int, boolean, boolean, boolean)
public CsvToBeanBuilder withVerifyReader(boolean verifyReader)
verifyReader
- Silence Javadoc warningsCSVReader.CSVReader(Reader, int, ICSVParser, boolean, boolean)
public CsvToBeanBuilder withSkipLines(int skipLines)
skipLines
- Silence Javadoc warningsCSVReader.CSVReader(Reader, int, ICSVParser, boolean, boolean)
public CsvToBeanBuilder withSeparator(char separator)
separator
- Silence Javadoc warningsCSVParser.CSVParser(char)
public CsvToBeanBuilder withQuoteChar(char quoteChar)
quoteChar
- Silence Javadoc warningsCSVParser.CSVParser(char, char)
public CsvToBeanBuilder withEscapeChar(char escapeChar)
escapeChar
- Silence Javadoc warningsCSVParser.CSVParser(char, char, char)
public CsvToBeanBuilder withStrictQuotes(boolean strictQuotes)
strictQuotes
- Silence Javadoc warningsCSVParser.CSVParser(char, char, char, boolean)
public CsvToBeanBuilder withIgnoreLeadingWhiteSpace(boolean ignoreLeadingWhiteSpace)
ignoreLeadingWhiteSpace
- Silence Javadoc warningsCSVParser.CSVParser(char, char, char, boolean, boolean)
public CsvToBeanBuilder withIgnoreQuotations(boolean ignoreQuotations)
ignoreQuotations
- Silence Javadoc warningsCSVParser.CSVParser(char, char, char, boolean, boolean, boolean)
public CsvToBeanBuilder withType(Class<? extends T> type)
withMappingStrategy(com.opencsv.bean.MappingStrategy)
is called.type
- Class of the destination beanHeaderColumnNameMappingStrategy.setType(java.lang.Class)
,
ColumnPositionMappingStrategy.setType(java.lang.Class)
public CsvToBeanBuilder withMultilineLimit(int multilineLimit)
multilineLimit
- No more than this number of lines is allowed in a
single input record. The default is CSVReader.DEFAULT_MULTILINE_LIMIT
.CSVReader.setMultilineLimit(int)
Copyright © 2017. All rights reserved.