Search in sources :

Example 1 with InstantiatorGetter

use of org.simpleflatmapper.reflect.getter.InstantiatorGetter in project SimpleFlatMapper by arnaudroger.

the class ConstantSourceFieldMapperFactoryImpl method getGettetInstantiator.

private <T, P> Getter<? super S, ? extends P> getGettetInstantiator(ClassMeta<P> classMeta, InstantiatorDefinition id, K key, FieldMapperColumnDefinition<K> columnDefinition, Collection<Type> types) {
    Instantiator<? super T, ? extends P> instantiator = classMeta.getReflectionService().getInstantiatorFactory().getOneArgIdentityInstantiator(id, classMeta.getReflectionService().builderIgnoresNullValues());
    final Type paramType = id.getParameters()[0].getGenericType();
    Getter<? super S, ? extends T> subGetter = getterFactory.newGetter(paramType, key, columnDefinition);
    if (subGetter == null) {
        if (types.contains(paramType)) {
            // loop circuit cutter
            return null;
        }
        types.add(paramType);
        // converter?
        Type sourceType = key.getType(paramType);
        Converter converter = converterService.findConverter(sourceType, paramType, columnDefinition.properties());
        if (converter != null) {
            Getter sourceTypeGetter = getterFactory.newGetter(sourceType, key, columnDefinition);
            subGetter = new GetterWithConverter(converter, sourceTypeGetter);
        } else {
            subGetter = lookForInstantiatorGetter(classMeta.getReflectionService().<T>getClassMeta(paramType), key, columnDefinition, types);
        }
    }
    if (subGetter != null) {
        return new InstantiatorGetter<T, S, P>(instantiator, subGetter);
    } else
        return null;
}
Also used : InstantiatorGetter(org.simpleflatmapper.reflect.getter.InstantiatorGetter) Type(java.lang.reflect.Type) Getter(org.simpleflatmapper.reflect.Getter) InstantiatorGetter(org.simpleflatmapper.reflect.getter.InstantiatorGetter) GetterWithConverter(org.simpleflatmapper.reflect.getter.GetterWithConverter) Converter(org.simpleflatmapper.converter.Converter) GetterWithConverter(org.simpleflatmapper.reflect.getter.GetterWithConverter)

Aggregations

Type (java.lang.reflect.Type)1 Converter (org.simpleflatmapper.converter.Converter)1 Getter (org.simpleflatmapper.reflect.Getter)1 GetterWithConverter (org.simpleflatmapper.reflect.getter.GetterWithConverter)1 InstantiatorGetter (org.simpleflatmapper.reflect.getter.InstantiatorGetter)1