When mapping a property sfm will looking for a getter/setter from the object to the source/target flat structure - ResultSet, Csv Row, etc …-. If it can’t find one it will then look for a Converter that gets transform to a supported type.
the default converter or in
sfm-converter |
the joda time one in
sfm-converter-joda-time |
the protobuf in
sfm-converter-protobuf |
It’s also possible to supply your own Converter<I, O> for a specific field by adding a ConverterProperty.
JdbcMapperFactory.newInstance()
.addColumnProperty("my_enum_column", ConverterProperty.of(MyEnum::factoryMethod))
.newMapper(MyClass.class);
you can also provide your converters using the ServiceLoader
- Create a
org.simpleflatmapper.converter.ConverterFactoryProducer
public class MyConverterFactoryProducer extends AbstractConverterFactoryProducer { @Override public void produce(Consumer<? super ConverterFactory<?, ?>> consumer) { constantConverter(consumer, Date.class, MyType.class, new DateToMyTypeConverter()); } }
- register the service in the
META-INF/services/org.simpleflatmapper.converter.ConverterFactoryProducer file
mypackage.MyConverterFactoryProducer
Note that providing a Converter does not guarantee it will be the one being used. The ConverterService will elect one according to path length and type matching. I you want to predictably changed the way a property is instantiated you will need to set a custom getter for that type