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:
CsvBindByPosition or CsvCustomBindByPosition is present,
ColumnPositionMappingStrategy is used.HeaderColumnNameMappingStrategy is used. This includes
the case when CsvBindByName or CsvCustomBindByName are being
used. The annotations will automatically be recognized.| Modifier and Type | Field and Description |
|---|---|
| private final CSVReader | csvReader
Allow the user to pass in a prebuilt/custom |
| private Locale | |
| private Character | |
| private CsvExceptionHandler | |
| private CsvToBeanFilter | |
| private final ListValuedMap | |
| private boolean | |
| private Boolean | |
| private Boolean | |
| private boolean | |
| private MappingStrategy | |
| private Integer | |
| private CSVReaderNullFieldIndicator | |
| private boolean | |
| private String | |
| private Character | |
| private final Reader | reader
A CSVReader will be built out of this |
| private Character | |
| private Integer | |
| private Boolean | |
| private Boolean | |
| private Class | |
| private final List | |
| private Boolean |
| Access | Constructor and Description |
|---|---|
| public | CsvToBeanBuilder(Reader
The reader that is the source of data for the CSV import reader)Constructor with the one parameter that is most definitely mandatory, and always will be. |
| public | CsvToBeanBuilder(CSVReader
The CSVReader that is the source of data for the CSV import csvReader)Constructor with the one parameter that is most definitely mandatory, and always will be. |
| Modifier and Type | Method and Description |
|---|---|
| public CsvToBean | |
| private CSVParser | Returns: An appropriateCSVParserBuilds a |
| private CSVReader | Returns: An appropriateCSVReaderThe parser)CSVParser necessary for this readerBuilds a |
| public CsvToBeanBuilder | Returns: thisLocale for error messages errorLocale)Sets the locale for all error messages. |
| public CsvToBeanBuilder | |
| public CsvToBeanBuilder | Returns: thisThe exception handler to be used. If exceptionHandler)null,
this method does nothing.Sets the handler for recoverable exceptions raised during processing of records. |
| public CsvToBeanBuilder | withFieldAsNull(CSVReaderNullFieldIndicator
Which field content will be returned as null: EMPTY_SEPARATORS, EMPTY_QUOTES,
BOTH, NEITHER (default) indicator)Returns: |
| public CsvToBeanBuilder | |
| public CsvToBeanBuilder | |
| public CsvToBeanBuilder | Returns: thisThe class opencsv will encounter the field in during
processing. In the case of inheritance, this may not be the
declaring class. type, Field The field opencsv is to ignore field)Adds a |
| public CsvToBeanBuilder | withIgnoreLeadingWhiteSpace(boolean
Please see the "See Also" section ignoreLeadingWhiteSpace)Returns: |
| public CsvToBeanBuilder | |
| public CsvToBeanBuilder | withKeepCarriageReturn(boolean
True to keep carriage returns in data read, false otherwise keepCR)Returns: |
| public CsvToBeanBuilder | withMappingStrategy(MappingStrategy<? extends T>
Please see the "See Also" section mappingStrategy)Returns: |
| public CsvToBeanBuilder | Returns: thisNo more than this number of lines is allowed in a
single input record. The default is multilineLimit)CSVReader#DEFAULT_MULTILINE_LIMIT.Sets the maximum number of lines allowed in a multiline record. |
| public CsvToBeanBuilder | Returns: thisWhether to order the results or not orderedResults)Sets whether the resulting beans must be ordered as in the input. |
| public CsvToBeanBuilder | Returns: thisThe name of the profile to be used profile)Selects a profile for deciding which configurations to use for the bean fields. |
| public CsvToBeanBuilder | |
| public CsvToBeanBuilder | |
| public CsvToBeanBuilder | |
| public CsvToBeanBuilder | |
| public CsvToBeanBuilder | Returns: thisPlease see the "See Also" section throwExceptions)Sets how the CsvToBean will act when an exception occurs. |
| public CsvToBeanBuilder | |
| public CsvToBeanBuilder | Returns: thisA new verifier that is to process all beans after
creation. verifier)null is permissible but has no effect.Adds a |
| public CsvToBeanBuilder |
| csvReader | back to summary |
|---|---|
| private final CSVReader csvReader Allow the user to pass in a prebuilt/custom | |
| errorLocale | back to summary |
|---|---|
| private Locale errorLocale | |
| escapeChar | back to summary |
|---|---|
private Character escapeChar
| |
| exceptionHandler | back to summary |
|---|---|
| private CsvExceptionHandler exceptionHandler | |
| filter | back to summary |
|---|---|
private CsvToBeanFilter filter
| |
| ignoredFields | back to summary |
|---|---|
| private final ListValuedMap<Class<?>, Field> ignoredFields | |
| ignoreEmptyLines | back to summary |
|---|---|
| private boolean ignoreEmptyLines | |
| ignoreLeadingWhiteSpace | back to summary |
|---|---|
| private Boolean ignoreLeadingWhiteSpace | |
| ignoreQuotations | back to summary |
|---|---|
| private Boolean ignoreQuotations | |
| keepCR | back to summary |
|---|---|
private boolean keepCR
| |
| mappingStrategy | back to summary |
|---|---|
| private MappingStrategy<? extends T> mappingStrategy | |
| multilineLimit | back to summary |
|---|---|
private Integer multilineLimit
| |
| nullFieldIndicator | back to summary |
|---|---|
| private CSVReaderNullFieldIndicator nullFieldIndicator | |
| orderedResults | back to summary |
|---|---|
| private boolean orderedResults | |
| profile | back to summary |
|---|---|
| private String profile | |
| quoteChar | back to summary |
|---|---|
private Character quoteChar
| |
| reader | back to summary |
|---|---|
| private final Reader reader A CSVReader will be built out of this
| |
| separator | back to summary |
|---|---|
private Character separator
| |
| skipLines | back to summary |
|---|---|
private Integer skipLines
| |
| strictQuotes | back to summary |
|---|---|
private Boolean strictQuotes
| |
| throwsExceptions | back to summary |
|---|---|
| private Boolean throwsExceptions | |
| type | back to summary |
|---|---|
private Class<? extends T> type
| |
| verifiers | back to summary |
|---|---|
private final List<BeanVerifier<T>> verifiers
| |
| verifyReader | back to summary |
|---|---|
private Boolean verifyReader
| |
| CsvToBeanBuilder | back to summary |
|---|---|
| public CsvToBeanBuilder(Reader reader) Constructor with the one parameter that is most definitely mandatory, and always will be.
| |
| CsvToBeanBuilder | back to summary |
|---|---|
| public CsvToBeanBuilder(CSVReader csvReader) Constructor with the one parameter that is most definitely mandatory, and always will be.
| |
| build | back to summary |
|---|---|
| public CsvToBean Builds the
| |
| buildParser | back to summary |
|---|---|
| private CSVParser buildParser() Builds a | |
| buildReader | back to summary |
|---|---|
| private CSVReader buildReader(CSVParser parser) Builds a | |
| withErrorLocale | back to summary |
|---|---|
| public CsvToBeanBuilder Sets the locale for all error messages.
| |
| withEscapeChar | back to summary |
|---|---|
public CsvToBeanBuilder
| |
| withExceptionHandler | back to summary |
|---|---|
| public CsvToBeanBuilder Sets the handler for recoverable exceptions raised during processing of
records. If both If neither this method nor Please note that if both this method and
| |
| withFieldAsNull | back to summary |
|---|---|
public CsvToBeanBuilder
| |
| withFilter | back to summary |
|---|---|
public CsvToBeanBuilder
| |
| withIgnoreEmptyLine | back to summary |
|---|---|
public CsvToBeanBuilder
| |
| withIgnoreField | back to summary |
|---|---|
| public CsvToBeanBuilder Adds a May be called as many times as necessary.
| |
| withIgnoreLeadingWhiteSpace | back to summary |
|---|---|
public CsvToBeanBuilder
| |
| withIgnoreQuotations | back to summary |
|---|---|
public CsvToBeanBuilder
| |
| withKeepCarriageReturn | back to summary |
|---|---|
public CsvToBeanBuilder
| |
| withMappingStrategy | back to summary |
|---|---|
public CsvToBeanBuilder
| |
| withMultilineLimit | back to summary |
|---|---|
| public CsvToBeanBuilder Sets the maximum number of lines allowed in a multiline record. More than this number in one record results in an IOException.
| |
| withOrderedResults | back to summary |
|---|---|
| public CsvToBeanBuilder Sets whether the resulting beans must be ordered as in the input.
| |
| withProfile | back to summary |
|---|---|
| public CsvToBeanBuilder Selects a profile for deciding which configurations to use for the bean fields.
| |
| withQuoteChar | back to summary |
|---|---|
public CsvToBeanBuilder
| |
| withSeparator | back to summary |
|---|---|
public CsvToBeanBuilder
| |
| withSkipLines | back to summary |
|---|---|
public CsvToBeanBuilder
| |
| withStrictQuotes | back to summary |
|---|---|
public CsvToBeanBuilder
| |
| withThrowExceptions | back to summary |
|---|---|
| public CsvToBeanBuilder Sets how the CsvToBean will act when an exception occurs. If both withThrowsExcpetion and
| |
| withType | back to summary |
|---|---|
| public CsvToBeanBuilder Sets the type of the bean to be populated.
Ignored if
| |
| withVerifier | back to summary |
|---|---|
| public CsvToBeanBuilder Adds a
| |
| withVerifyReader | back to summary |
|---|---|
public CsvToBeanBuilder
| |