public class CsvDozerBeanReader extends AbstractCsvReader implements ICsvDozerBeanReader
CsvBeanReader
that uses Dozer to map from CSV to a bean.Constructor and Description |
---|
CsvDozerBeanReader(ITokenizer tokenizer,
CsvPreference preferences)
Constructs a new CsvDozerBeanReader with the supplied (custom) Tokenizer and CSV preferences and creates
it's own DozerBeanMapper.
|
CsvDozerBeanReader(ITokenizer tokenizer,
CsvPreference preferences,
DozerBeanMapper dozerBeanMapper)
Constructs a new CsvDozerBeanReader with the supplied (custom) Tokenizer, CSV preferences and
DozerBeanMapper.
|
CsvDozerBeanReader(Reader reader,
CsvPreference preferences)
Constructs a new CsvDozerBeanReader with the supplied Reader and CSV preferences and creates it's own
DozerBeanMapper.
|
CsvDozerBeanReader(Reader reader,
CsvPreference preferences,
DozerBeanMapper dozerBeanMapper)
Constructs a new CsvDozerBeanReader with the supplied Reader, CSV preferences and DozerBeanMapper.
|
Modifier and Type | Method and Description |
---|---|
void |
configureBeanMapping(Class<?> clazz,
String[] fieldMapping)
Configures the underlying DozerBeanMapper with the mappings required to map from the CSV file to the specified
class (this method may only be called before reading, as it's not possible to configure a DozerBeanMapper that
has already been initialized).
|
void |
configureBeanMapping(Class<?> clazz,
String[] fieldMapping,
Class<?>[] hintTypes)
Configures the underlying DozerBeanMapper with the mappings required to map from the CSV file to the specified
class (this method may only be called before reading, as it's not possible to configure a DozerBeanMapper that
has already been initialized).
|
<T> T |
read(Class<T> clazz)
Reads a row of a CSV file and populates an instance of the specified class, using Dozer to map column values to
the appropriate fields.
|
<T> T |
read(Class<T> clazz,
CellProcessor... processors)
Reads a row of a CSV file and populates an instance of the specified class, using Dozer to map column values to
the appropriate fields.
|
<T> T |
read(T bean)
Reads a row of a CSV file and populates the supplied bean, using Dozer to map column values to the appropriate
fields.
|
<T> T |
read(T bean,
CellProcessor... processors)
Reads a row of a CSV file and populates the supplied bean, using Dozer to map column values to the appropriate
fields.
|
close, executeProcessors, get, getColumns, getHeader, getLineNumber, getPreferences, getRowNumber, getUntokenizedRow, length, readRow
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
get, getHeader, getLineNumber, getRowNumber, getUntokenizedRow, length
public CsvDozerBeanReader(Reader reader, CsvPreference preferences)
reader
- the readerpreferences
- the CSV preferencesNullPointerException
- if reader or preferences are nullpublic CsvDozerBeanReader(ITokenizer tokenizer, CsvPreference preferences)
tokenizer
- the tokenizerpreferences
- the CSV preferencesNullPointerException
- if tokenizer or preferences are nullpublic CsvDozerBeanReader(Reader reader, CsvPreference preferences, DozerBeanMapper dozerBeanMapper)
reader
- the readerpreferences
- the CSV preferencesdozerBeanMapper
- the dozer bean mapper to useNullPointerException
- if reader, preferences or dozerBeanMapper are nullpublic CsvDozerBeanReader(ITokenizer tokenizer, CsvPreference preferences, DozerBeanMapper dozerBeanMapper)
tokenizer
- the tokenizerpreferences
- the CSV preferencesdozerBeanMapper
- the dozer bean mapper to useNullPointerException
- if tokenizer, preferences or dozerBeanMapper are nullpublic void configureBeanMapping(Class<?> clazz, String[] fieldMapping)
Each element of the fieldMapping array represents a CSV column to be read and uses the standard Dozer field mapping syntax. For example, if you were configuring the mappings for Person class you might define firstName as the first element (just a simple field mapping), address.city as the second element (a nested - or deep - field mapping), and accounts[0].balance as the third element (index based mapping).
If you require access to the other features of Dozer in your mappings (customer getters/setters, bean factories, custom converters), then you should supply your own DozerBeanMapper to the Writer instead.
configureBeanMapping
in interface ICsvDozerBeanReader
clazz
- the class to add mapping configuration for (same as the type passed into write methods)fieldMapping
- the field mapping for for each column (may contain null elements to indicate ignored columns)public void configureBeanMapping(Class<?> clazz, String[] fieldMapping, Class<?>[] hintTypes)
Each element of the fieldMapping array represents a CSV column to be read and uses the standard Dozer field mapping syntax. For example, if you were configuring the mappings for Person class you might define firstName as the first element (just a simple field mapping), address.city as the second element (a nested - or deep - field mapping), and accounts[0].balance as the third element (index based mapping).
If you are mapping to an indexed list element (e.g. accounts[0]) and using a cell processor to return a custom bean type (e.g. a ParseAccount processor that creates an Account bean), you will need to specify a hint for that column so Dozer can map that column.
If you require access to the other features of Dozer in your mappings (customer getters/setters, bean factories, custom converters), then you should supply your own DozerBeanMapper to the Writer instead.
configureBeanMapping
in interface ICsvDozerBeanReader
clazz
- the class to add mapping configuration for (same as the type passed into write methods)fieldMapping
- the field mapping for for each column (may contain null elements to indicate ignored columns)hintTypes
- an array of types used as hints for Dozer when mapping to an indexed list element (e.g.
accounts[0]) - a null element indicates no hint is required for that columnpublic <T> T read(Class<T> clazz) throws IOException
read
in interface ICsvDozerBeanReader
T
- the bean typeclazz
- the type to instantiateIOException
- if an I/O error occurredpublic <T> T read(Class<T> clazz, CellProcessor... processors) throws IOException
read
in interface ICsvDozerBeanReader
T
- the bean typeclazz
- the type to instantiateprocessors
- the cell processorsIOException
- if an I/O error occurredpublic <T> T read(T bean) throws IOException
read
in interface ICsvDozerBeanReader
T
- the bean typebean
- the bean to populateIOException
- if an I/O error occurredpublic <T> T read(T bean, CellProcessor... processors) throws IOException
read
in interface ICsvDozerBeanReader
T
- the bean typebean
- the bean to populateprocessors
- the cell processorsIOException
- if an I/O error occurredCopyright © 2007–2015 Super CSV. All rights reserved.