Search in sources :

Example 1 with ContextualMapper

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);
    }
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) ContextualMapper(org.simpleflatmapper.map.mapper.ContextualMapper) CsvCellWriter(org.simpleflatmapper.csv.impl.writer.CsvCellWriter)

Aggregations

CsvCellWriter (org.simpleflatmapper.csv.impl.writer.CsvCellWriter)1 ContextualMapper (org.simpleflatmapper.map.mapper.ContextualMapper)1 FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)1