use of org.simpleflatmapper.map.property.EnumOrdinalFormatProperty in project SimpleFlatMapper by arnaudroger.
the class CsvWriterBuilderTest method testWriteCsvOnDbObject.
@Test
public void testWriteCsvOnDbObject() throws Exception {
MapperConfig<CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>> config = MapperConfig.<CsvColumnKey>fieldMapperConfig();
CsvWriterBuilder<DbObject> builder = CsvWriterBuilder.newBuilder(DbObject.class);
Mapper<DbObject, Appendable> mapper = builder.addColumn("id").addColumn("name").addColumn("email").addColumn("creation_time", new DateFormatProperty("dd/MM/yyyy HH:mm:ss")).addColumn("type_ordinal", new EnumOrdinalFormatProperty()).addColumn("type_name").mapper();
DbObject dbObject = CsvWriterTest.newDbObject();
assertEquals("13,name,email,06/06/2015 17:46:23,1,type3\r\n", mapper.map(dbObject).toString());
dbObject.setEmail("email,e\" ");
assertEquals("13,name,\"email,e\"\" \",06/06/2015 17:46:23,1,type3\r\n", mapper.map(dbObject).toString());
}
use of org.simpleflatmapper.map.property.EnumOrdinalFormatProperty in project SimpleFlatMapper by arnaudroger.
the class CsvWriterTest method testWriterWithFormatter.
@Test
public void testWriterWithFormatter() throws ParseException, IOException {
StringWriter sw = new StringWriter();
CsvWriter.from(DbObject.class).columns("id", "name").column("creation_time", new DateFormatProperty("dd/MM/yyyy")).column("type_ordinal", new EnumOrdinalFormatProperty()).to(sw).append(newDbObject());
assertEquals("id,name,creation_time,type_ordinal\r\n" + "13,name,06/06/2015,1\r\n", sw.toString());
}
Aggregations