Search in sources :

Example 1 with EnumOrdinalFormatProperty

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());
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) DbObject(org.simpleflatmapper.test.beans.DbObject) CsvColumnKey(org.simpleflatmapper.csv.CsvColumnKey) EnumOrdinalFormatProperty(org.simpleflatmapper.map.property.EnumOrdinalFormatProperty) DateFormatProperty(org.simpleflatmapper.map.property.DateFormatProperty) Test(org.junit.Test)

Example 2 with EnumOrdinalFormatProperty

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());
}
Also used : StringWriter(java.io.StringWriter) DbObject(org.simpleflatmapper.test.beans.DbObject) EnumOrdinalFormatProperty(org.simpleflatmapper.map.property.EnumOrdinalFormatProperty) DateFormatProperty(org.simpleflatmapper.map.property.DateFormatProperty) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 DateFormatProperty (org.simpleflatmapper.map.property.DateFormatProperty)2 EnumOrdinalFormatProperty (org.simpleflatmapper.map.property.EnumOrdinalFormatProperty)2 DbObject (org.simpleflatmapper.test.beans.DbObject)2 StringWriter (java.io.StringWriter)1 CsvColumnKey (org.simpleflatmapper.csv.CsvColumnKey)1 FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)1