Search in sources :

Example 1 with GetterWithConverter

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

the class ConstantSourceFieldMapperFactoryImpl method lookForAlternativeGetter.

private <P, J> Getter<? super S, ? extends P> lookForAlternativeGetter(ClassMeta<P> classMeta, K key, FieldMapperColumnDefinition<K> columnDefinition, Collection<Type> types) {
    // look for converter
    Type propertyType = classMeta.getType();
    Type sourceType = key.getType(propertyType);
    Object[] properties = columnDefinition.properties();
    Converter<? super J, ? extends P> converter = converterService.findConverter(sourceType, propertyType, properties);
    if (converter != null) {
        Getter<? super S, ? extends J> getter = getterFactory.newGetter(sourceType, key, properties);
        return new GetterWithConverter<S, J, P>(converter, getter);
    }
    return lookForInstantiatorGetter(classMeta, key, columnDefinition, types);
}
Also used : Type(java.lang.reflect.Type) GetterWithConverter(org.simpleflatmapper.reflect.getter.GetterWithConverter)

Example 2 with GetterWithConverter

use of org.simpleflatmapper.reflect.getter.GetterWithConverter 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)2 GetterWithConverter (org.simpleflatmapper.reflect.getter.GetterWithConverter)2 Converter (org.simpleflatmapper.converter.Converter)1 Getter (org.simpleflatmapper.reflect.Getter)1 InstantiatorGetter (org.simpleflatmapper.reflect.getter.InstantiatorGetter)1