Files
spring-boot-demo/mapstruct/output/09-builder-and-decorator.txt
T

32 lines
1.1 KiB
Plaintext

# Post-processing a record: @AfterMapping on its builder, or a @DecoratedWith decorator
--- ReceiptMapper: the hook receives ReceiptDto.Builder ---
ReceiptDto[orderId=100, total=32.50, summary=order 100: 2 line(s)]
public ReceiptDto toReceipt(Order order) {
if ( order == null ) {
return null;
}
ReceiptDto.Builder receiptDto = ReceiptDto.builder();
receiptDto.orderId( order.getId() );
receiptDto.total( orderMapper.sumOfLines( order.getLines() ) );
summarise( order, receiptDto );
return receiptDto.build();
}
--- InvoiceMapper: @DecoratedWith, so two beans implement the interface ---
bean invoiceMapperImpl -> InvoiceMapperImpl
bean invoiceMapperImpl_ -> InvoiceMapperImpl_
injected InvoiceMapper (the @Primary one) : InvoiceDto[id=100, status=PAID, total=32.50, display=#100 [PAID] 32.50]
the generated delegate on its own : InvoiceDto[id=100, status=PAID, total=32.50, display=null]
--- the generated class that decorates ---
@Component
@Primary
public class InvoiceMapperImpl extends InvoiceMapperDecorator {
}