Skip to content
Advertisement

MapStruct Java: property to list

Shortly, I’d like to move this code inside a mapstruct mapper:

JavaScript

I’d like to have:

JavaScript

Details

My source class:

JavaScript

where Results is:

JavaScript

And ResultType:

JavaScript

My Service class is getting a ResultSetType object from my Repository:

JavaScript

I need to map resultSetType to List<Provincia>.

So, I need to map resultSetType.results.result to List<Provincia>.

First of all, I’ve created a mapper in order to map ResultType to Provincia:

JavaScript

However, I can’t quite figure out how to travel from resultSetType.results.result to List<Provincia>.

Any ideas?

Advertisement

Answer

With MapStruct you can define mapping between different iterable. However, you can map from a nested listed into a top level list in a method (You can if it is wrapped though).

In any case for this I would suggest doing the following:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement