use of org.simpleflatmapper.map.property.DateFormatProperty 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());
}
use of org.simpleflatmapper.map.property.DateFormatProperty in project SimpleFlatMapper by arnaudroger.
the class CsvMapperDateFormatTest method testReadMultipleFormatOverrideDefault.
@Test
public void testReadMultipleFormatOverrideDefault() throws Exception {
String format1 = "dd/MM/yyyy";
String format2 = "MM-dd-yyyy";
CsvMapper<ObjectWithDate> mapper = CsvMapperFactory.newInstance().defaultDateFormat(format1).addColumnProperty(TRUE, new DateFormatProperty(format2)).newMapper(ObjectWithDate.class);
String data1 = "date1\n18/06/2016";
String data2 = "date1\n06-19-2016";
try {
mapper.forEach(new StringReader(data1), new ListCollector<ObjectWithDate>()).getList();
fail();
} catch (Exception e) {
//
}
List<ObjectWithDate> list = mapper.forEach(new StringReader(data2), new ListCollector<ObjectWithDate>()).getList();
assertEquals(1, list.size());
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
assertEquals(sdf.parse("20160619"), list.get(0).date1);
}
use of org.simpleflatmapper.map.property.DateFormatProperty in project SimpleFlatMapper by arnaudroger.
the class FieldMapperToAppendableFactoryTest method testJodaDateTimeWithDateFormat.
@Test
public void testJodaDateTimeWithDateFormat() throws Exception {
MappingContextFactoryBuilder<JodaObject, CsvColumnKey> builder = getMappingContextBuilder();
FieldMapperColumnDefinition<CsvColumnKey> format = FieldMapperColumnDefinition.<CsvColumnKey>identity().add(new DateFormatProperty("yyyyMMdd"));
FieldMapper<JodaObject, Appendable> fieldMapper = defaultFieldAppenderFactory.newFieldMapper(newPropertyMapping("dateTime", jodaObjectClassMeta, format), builder, null);
testFieldMapper("20140607", fieldMapper, jodaObject, builder.newFactory());
}
Aggregations