org.zodiac.autoconfigure.mapping.MappingAutoConfiguration Maven / Gradle / Ivy
package org.zodiac.autoconfigure.mapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.zodiac.commons.constants.SystemPropertiesConstants;
import org.zodiac.commons.mapping.config.MappingRegister;
@SpringBootConfiguration
// @EnableConfigurationProperties(MappingProperties.class)
@ConditionalOnClass(name = {"ma.glasnost.orika.MapperFactory"})
@ComponentScan(basePackages = {"org.zodiac.mapping", "org.zodiac.commons.mapping"})
public class MappingAutoConfiguration {
protected Logger log = LoggerFactory.getLogger(getClass());
@Bean
@ConfigurationProperties(prefix = SystemPropertiesConstants.Zodiac.PLATFORM_MAPPING_PREFIX)
protected MappingProperties mappingProperties() {
return new MappingProperties();
}
@Bean
@ConditionalOnMissingBean
protected ma.glasnost.orika.MapperFactory mapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory.MapperFactoryBuilder, ?> mapperFactoryBuilder) {
ma.glasnost.orika.MapperFactory mapperFactory = mapperFactoryBuilder.build();
return mapperFactory;
}
@Bean
@ConditionalOnMissingBean
protected ma.glasnost.orika.MapperFacade mapperFacade(ma.glasnost.orika.MapperFactory mapperFactory) {
return mapperFactory.getMapperFacade();
}
@Bean
@ConditionalOnMissingBean
protected ma.glasnost.orika.impl.DefaultMapperFactory.MapperFactoryBuilder, ?> mapperFactoryBuilder(MappingProperties properties) {
ma.glasnost.orika.impl.DefaultMapperFactory.Builder builder = new ma.glasnost.orika.impl.DefaultMapperFactory.Builder();
builder.useBuiltinConverters(properties.isUseBuiltinConverters())
.useAutoMapping(properties.isUseAutoMapping())
.mapNulls(properties.isMapNulls())
.dumpStateOnException(properties.isDumpStateOnException())
.favorExtension(properties.isFavorExtension())
.captureFieldContext(properties.isCaptureFieldContext());
log.debug("MappingProperties: {}", properties);
return builder;
}
@Bean
protected MappingRegister mappingRegister(ma.glasnost.orika.MapperFactory mapperFactory) {
return new MappingRegister(mapperFactory);
}
}