use of org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder in project SimpleFlatMapper by arnaudroger.
the class ConstantSourceMapperBuilderTest method testMapInnerObjectWithMapper.
@Test
public void testMapInnerObjectWithMapper() throws Exception {
ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey> constantSourceMapperBuilder = new ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey>(mapperSource, classMeta, MapperConfig.config(new IdentityFieldMapperColumnDefinitionProvider<SampleFieldKey>()), new MappingContextFactoryBuilder<Object, SampleFieldKey>(null), SampleFieldKey.KEY_FACTORY);
constantSourceMapperBuilder.addMapping(new SampleFieldKey("prop_date", 0), FieldMapperColumnDefinition.<SampleFieldKey>identity());
Mapper<Object, MyObjectWithInner> mapper = constantSourceMapperBuilder.mapper();
MyObjectWithInner o = mapper.map(null);
assertEquals(DATE, o.prop.date);
assertNull(o.prop.str);
}
use of org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder in project SimpleFlatMapper by arnaudroger.
the class ConstantSourceMapperBuilderTest method testFieldMapperErrorHandler.
@Test
public void testFieldMapperErrorHandler() throws Exception {
ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey> constantSourceMapperBuilder = new ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey>(mapperSource, classMeta, MapperConfig.config(new IdentityFieldMapperColumnDefinitionProvider<SampleFieldKey>()).fieldMapperErrorHandler(new FieldMapperErrorHandler<SampleFieldKey>() {
@Override
public void errorMappingField(SampleFieldKey key, Object source, Object target, Exception error) throws MappingException {
}
}), new MappingContextFactoryBuilder<Object, SampleFieldKey>(null), SampleFieldKey.KEY_FACTORY);
constantSourceMapperBuilder.addMapping(new SampleFieldKey("prop_date", 16), FieldMapperColumnDefinition.<SampleFieldKey>identity());
Mapper<Object, MyObjectWithInner> mapper = constantSourceMapperBuilder.mapper();
MyObjectWithInner o = mapper.map(null);
System.out.println("mapper = " + mapper);
assertNull(o.prop);
}
use of org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder in project SimpleFlatMapper by arnaudroger.
the class DatastaxUDTGetter method newFieldMapperBuilder.
public static <P> ConstantSourceMapperBuilder<GettableByIndexData, P, DatastaxColumnKey> newFieldMapperBuilder(DatastaxMapperFactory factory, Type target) {
MapperConfig<DatastaxColumnKey, FieldMapperColumnDefinition<DatastaxColumnKey>> config = factory.mapperConfig();
MapperSourceImpl<GettableByIndexData, DatastaxColumnKey> mapperSource = new MapperSourceImpl<GettableByIndexData, DatastaxColumnKey>(GettableByIndexData.class, new RowGetterFactory(factory));
ClassMeta<P> classMeta = factory.getClassMeta(target);
return new ConstantSourceMapperBuilder<GettableByIndexData, P, DatastaxColumnKey>(mapperSource, classMeta, config, new DatastaxMappingContextFactoryBuilder(), DatastaxMapperBuilder.KEY_FACTORY);
}
use of org.simpleflatmapper.map.mapper.ConstantSourceMapperBuilder in project SimpleFlatMapper by arnaudroger.
the class ConstantSourceMapperBuilderTest method testAnonymousParameterWithDifferentType.
@Test
public void testAnonymousParameterWithDifferentType() throws Exception {
ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey> constantSourceMapperBuilder = new ConstantSourceMapperBuilder<Object, MyObjectWithInner, SampleFieldKey>(mapperSource, classMeta, MapperConfig.config(new IdentityFieldMapperColumnDefinitionProvider<SampleFieldKey>()), new MappingContextFactoryBuilder<Object, SampleFieldKey>(null), SampleFieldKey.KEY_FACTORY);
constantSourceMapperBuilder.addMapping(new SampleFieldKey("prop", 0, Date.class), FieldMapperColumnDefinition.<SampleFieldKey>identity());
Mapper<Object, MyObjectWithInner> mapper = constantSourceMapperBuilder.mapper();
MyObjectWithInner o = mapper.map(null);
assertEquals(DATE, o.prop.date);
assertNull(o.prop.str);
}
Aggregations