io.beanmapper.spring.converter.BeanMapperConverterAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of beanmapper-spring Show documentation
Show all versions of beanmapper-spring Show documentation
Spring support for the Bean Mapper
package io.beanmapper.spring.converter;
import java.util.Collections;
import java.util.Set;
import io.beanmapper.BeanMapper;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.core.convert.converter.GenericConverter;
/**
* Adapter that allows the bean mapper to be used in
* the spring conversion service.
*
* @author Jeroen van Schagen
* @since Aug 21, 2015
*/
public class BeanMapperConverterAdapter implements GenericConverter {
/**
* Delegate bean mapper.
*/
private final BeanMapper beanMapper;
/**
* Construct a new instance.
* @param beanMapper the bean mapper
*/
public BeanMapperConverterAdapter(BeanMapper beanMapper) {
this.beanMapper = beanMapper;
}
/**
* {@inheritDoc}
*/
@Override
public Set getConvertibleTypes() {
return Collections.singleton(new ConvertiblePair(Object.class, Object.class));
}
/**
* {@inheritDoc}
*/
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
if (sourceType.getType().equals(targetType.getType())) {
return source;
}
return beanMapper.map(source, targetType.getType());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy