use of org.simpleflatmapper.reflect.setter.SetterOnGetter in project SimpleFlatMapper by arnaudroger.
the class FieldMapperToAppendableFactory method setterFromFactory.
@SuppressWarnings("unchecked")
private <S, P> Setter<Appendable, ? super P> setterFromFactory(PropertyMapping<S, P, CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>> pm) {
Setter<Appendable, ? super P> setter = null;
final SetterFactoryProperty setterFactoryProperty = pm.getColumnDefinition().lookFor(SetterFactoryProperty.class);
if (setterFactoryProperty != null) {
final SetterFactory<Appendable, PropertyMapping<S, P, CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>>> setterFactory = (SetterFactory<Appendable, PropertyMapping<S, P, CsvColumnKey, FieldMapperColumnDefinition<CsvColumnKey>>>) setterFactoryProperty.getSetterFactory();
setter = setterFactory.getSetter(pm);
}
if (setter == null) {
if (!pm.getPropertyMeta().isSelf()) {
final ClassMeta<P> classMeta = pm.getPropertyMeta().getPropertyClassMeta();
if (classMeta instanceof ObjectClassMeta) {
ObjectClassMeta<P> ocm = (ObjectClassMeta<P>) classMeta;
if (ocm.getNumberOfProperties() == 1) {
PropertyMeta<P, ?> subProp = ocm.getFirstProperty();
Setter<Appendable, Object> subSetter = (Setter<Appendable, Object>) setterFromFactory(pm.propertyMeta(subProp));
if (subSetter != null) {
setter = new SetterOnGetter<Appendable, Object, P>(subSetter, (Getter<P, Object>) subProp.getGetter());
} else {
return new ObjectToStringSetter<P>(subProp.getGetter());
}
}
}
}
}
return setter;
}
Aggregations