use of org.simpleflatmapper.map.mapper.ContextualMapper in project SimpleFlatMapper by arnaudroger.
the class CsvWriter method from.
/**
* Create a DSL on the specified type.
* @param type the type of object to write
* @param <T> the type
* @return a DSL on the specified type
*/
public static <T> CsvWriterDSL<T> from(Type type) {
ClassMeta<T> classMeta = ReflectionService.newInstance().getClassMeta(type);
CellWriter cellWriter = CsvCellWriter.DEFAULT_WRITER;
CsvWriterBuilder<T> builder = CsvWriterBuilder.newBuilder(classMeta, cellWriter);
MapperConfig<CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>> mapperConfig = MapperConfig.<CsvColumnKey>fieldMapperConfig();
try {
String[] headers = defaultHeaders(classMeta);
for (String header : headers) {
builder.addColumn(header);
}
ContextualMapper<T, Appendable> mapper = (ContextualMapper<T, Appendable>) builder.mapper();
return new DefaultCsvWriterDSL<T>(CsvWriter.<T>toColumnDefinitions(headers), cellWriter, mapper, classMeta, mapperConfig, false);
} catch (UnsupportedOperationException e) {
return new NoColumnCsvWriterDSL<T>(cellWriter, classMeta, mapperConfig, false);
}
}
Aggregations