public class CsvDozerBeanWriter extends AbstractCsvWriter implements ICsvDozerBeanWriter
CsvBeanWriter
that uses Dozer to map from a bean to CSV.Constructor and Description |
---|
CsvDozerBeanWriter(Writer writer,
CsvPreference preference)
Constructs a new CsvDozerBeanWriter with the supplied Writer and CSV preferences and and creates it's
own DozerBeanMapper.
|
CsvDozerBeanWriter(Writer writer,
CsvPreference preference,
DozerBeanMapper dozerBeanMapper)
Constructs a new CsvDozerBeanWriter with the supplied Writer, 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 specified class to the CSV
file (this method may only be called before writing, as it's not possible to configure a DozerBeanMapper that has
already been initialized).
|
void |
write(Object source)
Writes the fields of the object as columns of a CSV file, using the pre-configured DozerBeanMapper to map fields
to the appropriate columns.
|
void |
write(Object source,
CellProcessor[] processors)
Writes the fields of the object as columns of a CSV file, using the pre-configured DozerBeanMapper to map fields
to the appropriate columns.
|
close, flush, getLineNumber, getRowNumber, incrementRowAndLineNo, writeComment, writeHeader, writeRow, writeRow, writeRow
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getLineNumber, getRowNumber, writeComment, writeHeader
public CsvDozerBeanWriter(Writer writer, CsvPreference preference)
writer
- the writerpreference
- the CSV preferencesNullPointerException
- if writer or preference are nullpublic CsvDozerBeanWriter(Writer writer, CsvPreference preference, DozerBeanMapper dozerBeanMapper)
writer
- the writerpreference
- the CSV preferencesdozerBeanMapper
- the pre-configured DozerBeanMapperNullPointerException
- if writer, preference or dozerBeanMapper are nullpublic void configureBeanMapping(Class<?> clazz, String[] fieldMapping)
Each element of the fieldMapping array represents a CSV column to be written 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 ICsvDozerBeanWriter
clazz
- the class to add mapping configuration for (same as the type passed into write methods)fieldMapping
- the field mapping for for each column (cannot contain null elements)public void write(Object source) throws IOException
write
in interface ICsvDozerBeanWriter
source
- the object (bean instance) containing the values to writeIOException
- if an I/O error occurredpublic void write(Object source, CellProcessor[] processors) throws IOException
Before writing, the data can be further processed by cell processors (each element in the processors array corresponds with a CSV column). A null entry in the processors array indicates no further processing is required (the value returned by toString() will be written as the column value). toString() will be called on each (processed) element prior to writing.
write
in interface ICsvDozerBeanWriter
source
- the object (bean instance) containing the values to writeprocessors
- an array of CellProcessors used to further process data before it is written (each element in the
processors array corresponds with a CSV column - the number of processors should match the number of
columns). A null entry indicates no further processing is required (the value returned by
toString() will be written as the column value).IOException
- if an I/O error occurredCopyright © 2007–2015 Super CSV. All rights reserved.