Search in sources :

Example 6 with CsvMapperBuilder

use of org.simpleflatmapper.csv.CsvMapperBuilder in project SimpleFlatMapper by arnaudroger.

the class CsvMapperBuilderSubObjectTest method testMapDbObjectWithCustomReader.

@Test
public void testMapDbObjectWithCustomReader() throws Exception {
    CsvMapperBuilder<Db1DeepObject> builder = new CsvMapperBuilder<Db1DeepObject>(Db1DeepObject.class, ReflectionService.newInstance(false));
    CsvColumnDefinition columnDefinition = CsvColumnDefinition.customReaderDefinition(new CellValueReader<String>() {

        @Override
        public String read(char[] chars, int offset, int length, ParsingContext parsingContext) {
            return "cv1";
        }
    });
    builder.addMapping("db_Object_name", columnDefinition);
    CsvMapper<Db1DeepObject> mapper = builder.mapper();
    Db1DeepObject v1 = mapper.iterator(new StringReader("v1")).next();
    assertEquals("cv1", v1.getDbObject().getName());
}
Also used : Db1DeepObject(org.simpleflatmapper.test.beans.Db1DeepObject) ParsingContext(org.simpleflatmapper.csv.ParsingContext) CsvMapperBuilder(org.simpleflatmapper.csv.CsvMapperBuilder) StringReader(java.io.StringReader) CsvColumnDefinition(org.simpleflatmapper.csv.CsvColumnDefinition) Test(org.junit.Test)

Example 7 with CsvMapperBuilder

use of org.simpleflatmapper.csv.CsvMapperBuilder in project SimpleFlatMapper by arnaudroger.

the class CsvMapperBuilderSubObjectTest method testMapDbFinalObject.

@Test
public void testMapDbFinalObject() throws Exception {
    CsvMapperBuilder<DbFinal1DeepObject> builder = new CsvMapperBuilder<DbFinal1DeepObject>(DbFinal1DeepObject.class);
    addDbObjectFields(builder);
    CsvMapper<DbFinal1DeepObject> mapper = builder.mapper();
    List<DbFinal1DeepObject> list = mapper.forEach(db1deepObjectCsvReader(), new ListCollector<DbFinal1DeepObject>()).getList();
    assertEquals(1, list.size());
    DbFinal1DeepObject o = list.get(0);
    assertEquals(1234, o.getId());
    assertEquals("val!", o.getValue());
    DbHelper.assertDbObjectMapping(o.getDbObject());
}
Also used : ListCollector(org.simpleflatmapper.util.ListCollector) CsvMapperBuilder(org.simpleflatmapper.csv.CsvMapperBuilder) DbFinal1DeepObject(org.simpleflatmapper.test.beans.DbFinal1DeepObject) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)7 CsvMapperBuilder (org.simpleflatmapper.csv.CsvMapperBuilder)7 ListCollector (org.simpleflatmapper.util.ListCollector)4 StringReader (java.io.StringReader)3 Db1DeepObject (org.simpleflatmapper.test.beans.Db1DeepObject)2 Db1DeepPartialObject (org.simpleflatmapper.test.beans.Db1DeepPartialObject)2 CsvColumnDefinition (org.simpleflatmapper.csv.CsvColumnDefinition)1 ParsingContext (org.simpleflatmapper.csv.ParsingContext)1 DbFinal1DeepObject (org.simpleflatmapper.test.beans.DbFinal1DeepObject)1