I try to config Orika mapper. I have 5 entities and 5 DTO. My configuration work true, but I can't find any information about how to configure mapper for different classes. So is it possible to create one configuration for some classes or I should create configuration for every pair of classes?
@Configuration
public class MapperConfig implements OrikaMapperFactoryConfigurer {
@Bean
DatatypeFactory datatypeFactory() throws DatatypeConfigurationException {
return DatatypeFactory.newInstance();
}
@Bean
DefaultMapperFactory.MapperFactoryBuilder<?, ?> orikaMapperFactoryBuilder() {
DefaultMapperFactory.Builder orikaMapperFactoryBuilder = new DefaultMapperFactory.Builder();
return orikaMapperFactoryBuilder;
}
@Bean
public MapperFactory orikaMapperFactory(DefaultMapperFactory.MapperFactoryBuilder<?, ?> orikaMapperFactoryBuilder) {
MapperFactory orikaMapperFactory = orikaMapperFactoryBuilder.build();
this.configure(orikaMapperFactory);
return orikaMapperFactory;
}
public void configure(MapperFactory orikaMapperFactory) {
orikaMapperFactory.classMap(Author.class, AuthorDto.class)
.byDefault()
.register();
}
@Bean
public MapperFacade orikaMapperFacade(MapperFactory orikaMapperFactory) {
MapperFacade orikaMapperFacade = orikaMapperFactory.getMapperFacade();
return orikaMapperFacade;
}
}
Yes you can, you need to register mapper for other two pairs of classes in configure method
Example:
public void configure(MapperFactory orikaMapperFactory) {
orikaMapperFactory.classMap(Author.class, AuthorDto.class)
.byDefault()
.register();
orikaMapperFactory.classMap(A.class, B.class)
.byDefault()
.register();
}