IterableMapping with additional shared value

46 views
Skip to first unread message

Baptiste Pernet

unread,
Oct 21, 2021, 5:11:59 PM10/21/21
to mapstru...@googlegroups.com
Hello, I wanted to run this problem by the community to see what's the best way of doing this.

Here is what I have done so far.

interface SellerMapper {

  @Mapping(target = "sellers", source = "sellers")
  ProductDto toProductDto(Product product);

  default List<SellerDto> toSellerDtos(Product product) {
    if (product == null || product.getSellers() == null) {
      return null;
    }
    List<SellerDto> sellers = toSellerDtos(product.getSellers());
    sellers.forEach(seller -> seller.setProductId(product.getId()));
    return sellers
  }

  List<SellerDto> toSellerDtos(List<Seller> sellers);

  @Mapping(target = "id", source = "id")
  @Mapping(target = "productId", ignore = true)
  SellerDto toSellerDto(Seller seller);
}

I don't really like the method List<SellerDto> toSellerDtos(Product product)
and I would like to see how I could do that differently. I tried with an @AfterMapping but with no success.

Warm Regards
--
Baptiste
Reply all
Reply to author
Forward
0 new messages