Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider to use addAll for mapping from Iterabale. #320

Open
AndreiPetrooshin opened this issue May 18, 2023 · 0 comments
Open

Consider to use addAll for mapping from Iterabale. #320

AndreiPetrooshin opened this issue May 18, 2023 · 0 comments

Comments

@AndreiPetrooshin
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant