package ...; import org.modelmapper.Provider; import org.modelmapper.Provider.ProvisionRequest; import org.modelmapper.internal.util.Assert; import org.springframework.beans.factory.BeanFactory; public class EnhancedModelMapperSpringIntegration { private static class SpringProvider<S, D> implements Provider<D> { BeanFactory beanFactory; SourceBeanFactoryMapper<S, D> sourceBeanFactoryMapper; SpringProvider(BeanFactory beanFactory, SourceBeanFactoryMapper<S, D> sourceBeanFactoryMapper) { this.beanFactory = beanFactory; this.sourceBeanFactoryMapper = sourceBeanFactoryMapper; } @Override public D get(ProvisionRequest<D> request) { return sourceBeanFactoryMapper.map((S)request.getSource(), beanFactory); } } public static <S, D> Provider<?> fromSpring(BeanFactory beanFactory, SourceBeanFactoryMapper<S, D> sourceBeanFactoryMapper) { Assert.notNull(beanFactory); return new SpringProvider(beanFactory, sourceBeanFactoryMapper); } } package ...; import org.springframework.beans.factory.BeanFactory; public interface SourceBeanFactoryMapper<S, D> { D map(S s, BeanFactory beanFactory); }
Friday, July 25, 2014
ModelMapper Generic Spring Integration
The Spring integration provided by ModelMapper (http://modelmapper.org/user-manual/spring-integration/) as of now could be enhanced as below in order to provide capability to pass in a delegate interface to use during setup:
Labels:
Java,
ModelMapper,
Spring
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment