org.simpleflatmapper.map.impl.GetterMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-map Show documentation
Show all versions of sfm-map Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.simpleflatmapper.map.impl;
import org.simpleflatmapper.map.FieldMapper;
import org.simpleflatmapper.map.MappingContext;
import org.simpleflatmapper.map.MappingException;
import org.simpleflatmapper.map.SourceMapper;
import org.simpleflatmapper.map.getter.ContextualGetter;
import org.simpleflatmapper.util.ErrorHelper;
public final class GetterMapper implements SourceMapper, FieldMapper {
private final ContextualGetter super S, P> getter;
public GetterMapper(ContextualGetter super S, P> getter) {
this.getter = getter;
}
@Override
public P map(S source, MappingContext super S> context) throws MappingException {
try {
return getter.get(source, context);
} catch (Exception e) {
return ErrorHelper.rethrow(e);
}
}
@Override
public void mapTo(S source, P target, MappingContext super S> context) throws Exception {
// cannot map to an object
}
}