All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.simpleflatmapper.map.mapper.FieldErrorHandlerMapper Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 9.0.2
Show newest version
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 errorHandler;
	public final K key;
	
	public FieldErrorHandlerMapper(K key, FieldMapper delegate,
			FieldMapperErrorHandler errorHandler) {
		super();
		this.key = key;
		this.delegate = delegate;
		this.errorHandler = errorHandler;
	}

	@Override
	public void mapTo(S source, T target, MappingContext 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 errorHandler) {
		return new FieldErrorHandlerMapper(key, delegate, errorHandler);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy