Hi, I have the following situation:
I need to map Entity object from Customer object (protos).
@Mapping(target = "document", qualifiedByName = "mapToDocuments", source = "customer")
Entity mapToEntity(Customer customer);
@Named("mapToDocuments")
public List<Document> mapToDocuments(Customer customer) {
List<Document> documents = new ArrayList<>();
documents.add(mapToDocument1(customer.getDocument()));
documents.add(mapToDocument2(customer.phone()));
return documents;
}
The main problem, that I have to create 2 Documents from 2 different fields of Customer objects.
But this approach doesn't work since mapper looking for method with return type Document instead of List.
Currently using CollectionMappingStrategy.ADDER_PREFERRED we can map only from (Customer.List<Document> or Document) to Entity.List<Document> in both cases entity.addDocument(Document document) will be used.
Can we tell somehow mapstruct to use addAll when we specify qualifiedByName which returns List<Docuement>?
Or maybe you can suggest other ways to get around this problem?
Hi, I have the following situation:
I need to map Entity object from Customer object (protos).
The main problem, that I have to create 2 Documents from 2 different fields of Customer objects.
But this approach doesn't work since mapper looking for method with return type Document instead of List.
Currently using
CollectionMappingStrategy.ADDER_PREFERREDwe can map only from (Customer.List<Document>orDocument) toEntity.List<Document>in both casesentity.addDocument(Document document)will be used.Can we tell somehow mapstruct to use addAll when we specify qualifiedByName which returns
List<Docuement>?Or maybe you can suggest other ways to get around this problem?