org.simpleflatmapper.map.mapper.FieldErrorHandlerMapper 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.mapper;
import org.simpleflatmapper.map.FieldKey;
import org.simpleflatmapper.map.FieldMapper;
import org.simpleflatmapper.map.FieldMapperErrorHandler;
import org.simpleflatmapper.map.MappingContext;
public final class FieldErrorHandlerMapper implements FieldMapper {
public final FieldMapper delegate;
public final FieldMapperErrorHandler super K> errorHandler;
public final K key;
public FieldErrorHandlerMapper(K key, FieldMapper delegate,
FieldMapperErrorHandler super K> errorHandler) {
super();
this.key = key;
this.delegate = delegate;
this.errorHandler = errorHandler;
}
@Override
public void mapTo(S source, T target, MappingContext super S> mappingContext) {
try {
delegate.mapTo(source, target, mappingContext);
} catch(Exception e) {
errorHandler.errorMappingField(key, source, target, e, mappingContext);
}
}
@Override
public String toString() {
return "FieldErrorHandlerMapper{delegate=" + delegate + '}';
}
public static > FieldMapper of(K key, FieldMapper delegate,
FieldMapperErrorHandler super K> errorHandler) {
return new FieldErrorHandlerMapper(key, delegate, errorHandler);
}
}