cz.jalasoft.lifeconfig.converterprovider.ConverterAnnotationProvider Maven / Gradle / Ivy
package cz.jalasoft.lifeconfig.converterprovider;
import cz.jalasoft.lifeconfig.annotation.Converter;
import cz.jalasoft.lifeconfig.converter.CollectionConverter;
import java.lang.reflect.Method;
import java.util.Collection;
/**
* This provider looks for the annotation {@link Converter}
* on a method to provide an instance of a converter by a
* class defined in the annotation. Otherwise it delegates
* to another provider.
*
* @author Honza Lastovicka ([email protected])
* @since 2016-09-19.
*/
public final class ConverterAnnotationProvider implements ConverterProvider {
private final ConverterProvider decorated;
public ConverterAnnotationProvider(ConverterProvider decorated) {
this.decorated = decorated;
}
@Override
public cz.jalasoft.lifeconfig.converter.Converter converter(Object sourceValue, Method method) throws ConverterNotFoundException {
if (!method.isAnnotationPresent(Converter.class)) {
return decorated.converter(sourceValue, method);
}
Converter annotation = method.getAnnotation(Converter.class);
cz.jalasoft.lifeconfig.converter.Converter