The original idea is from https://www.tutorialspoint.com/mapstruct/mapstruct_mapping_nested_bean.htm
The original idea is from
https://medium.com/@nina.trausner/mapstruct-different-approaches-and-best-practices-282adbb96838
The original idea is from
https://raphaeldelio.medium.com/aftermapping-updating-lists-or-custom-objects-with-mapstruct-in-java-4a6f4622ef92
The original idea is from
https://medium.com/@tecnicorabi/mastering-mapstruct-for-efficient-java-bean-mappings-f03ddd9b511b
@Mapper
public interface ProductMapper {
@Mapping(source = "priceEuro", target = "price")
Product productDTOToProduct(ProductDTO productDTO);
}
@Mapper
public interface UserMapper {
@Mapping(target = "id", ignore = true)
UserDTO createUserDTOWithoutId(User user);
}
@Mapper
public interface ProductMapper {
@Mapping(target = "totalPrice", expression = "java(product.getPrice() * 1.08)")
ProductDTO productToProductDTO(Product product);
}
@Mapper
public interface ProductMapper {
List<ProductDTO> productsToProductDTOs(List<Product> products);
}
@Mapper(uses = ProductMapper.class)
public interface OrderMapper {
OrderDTO orderToOrderDTO(Order order);
}
@Mapper
public interface OrderMapper {
OrderDTO orderToOrderDTO(Order order);
@ValueMappings({
@ValueMapping(source = "PROCESSING", target = "PENDING"),
@ValueMapping(source = "SHIPPED", target = "COMPLETED"),
@ValueMapping(source = "DELIVERED", target = "CANCELLED")
})
OrderStatusDTO mapOrderStatusToOrderStatusDTO(OrderStatus orderStatus);
}
@Mapper
public interface ProductMapper {
@Mapping(target = "price", source = "price", defaultValue = "0.0")
ProductDTO productToProductDTO(Product product);
}
@Mapper
public interface ProductMapper {
@Mapping(target = "manufactureDate", source = "manufactureDate", qualifiedByName = "stringToLocalDate")
Product productDTOToProduct(ProductDTO productDTO);
@Named("stringToLocalDate")
default LocalDate stringToLocalDate(String date) {
return LocalDate.parse(date);
}
}