Skip to content

Latest commit

 

History

History
executable file
·
46 lines (27 loc) · 828 Bytes

README.md

File metadata and controls

executable file
·
46 lines (27 loc) · 828 Bytes

Generic Mapper

A helper project to access Mapstruct created mapper s with source and target types.

Usage

  • Create model and dto objects.
public class Fruit {
}

public class FruitDto {
}
  • Create a Mapstruct mapper which extends GenericMapper interface.
@Mapper( componentModel="spring" )
public interface FruitMapper extends GenericMapper<Fruit, FruitDto> {
}
  • Inject GenericMapperService to your service and lookup for the mapper.
@Autowired
private GenericMapperService mapperService;

GenericMapper<Fruit, FruitDto> mapper = mapperService.getMapper( Fruit.class, FruitDto.class );
  • You can also inject your GenericMapper to your services directly with Spring's injection capabilities.
@Autowired
GenericMapper<Fruit, FruitDto> fruitMapper;