Hi All,
I might be thinking about this all wrong but I don't seem to be able to find ANY example or information that seem to fit what I am looking to do. This is my first time using mapstruct and so far its been great.
currently I have three Entities that I am able to a single DTO which I then use as a combined objected to return a nested DTO. I can query the controller and I get one object back.
The issue
I cannot find how I am able to do the above for ALL items within the three entities as lists. where within the Mapper, pass three lists as sources and convert them to a list of DTO.
it is also possible that I am thinking about this who mapping issue completely wrong.
What I have for one object
@Mapping(source = "
a.id", target = "id")
@Mapping(source = "a.status", target = "status")
@Mapping(source = "a.statusDate", target = "statusDate")
@Mapping(source = "b.firstName", target = "b.firstName")
@Mapping(source = "b.lastName", target = "b.lastName")
@Mapping(source = "b.email", target = "b.email")
@Mapping(source = "c.userId", target = "c.userId")
@Mapping(source = "c.loginId", target = "c.loginId")
CombinedDto EntityToDTO(AEntity a, BEntity b, CEntity c);
What I have for one list from one entity List
List<CombinedDto> EntityListToDTOList(List<AEntity> a);
Is it possible to do something like? (I am also guessing the mappings here might be wrong)
@Mapping(source = "
a.id", target = "id")
@Mapping(source = "a.status", target = "status")
@Mapping(source = "a.statusDate", target = "statusDate")
@Mapping(source = "b.firstName", target = "b.firstName")
@Mapping(source = "b.lastName", target = "b.lastName")
@Mapping(source = "b.email", target = "b.email")
@Mapping(source = "c.userId", target = "c.userId")
@Mapping(source = "c.loginId", target = "c.loginId")
List<CombinedDto> EntityListToDTOList(List<AEntity> a, List<BEntity> b,List<CEntity> c);
What I essentially need is a mapper for a list of the below
@Mapping(source = "
a.id", target = "id")
@Mapping(source = "a.status", target = "status")
@Mapping(source = "a.statusDate", target = "statusDate")
@Mapping(source = "b.firstName", target = "b.firstName")
@Mapping(source = "b.lastName", target = "b.lastName")
@Mapping(source = "b.email", target = "b.email")
@Mapping(source = "c.userId", target = "c.userId")
@Mapping(source = "c.loginId", target = "c.loginId")
CombinedDto EntityToDTO(AEntity a, BEntity b, CEntity c);
I hope this makes sense and thanks in advance for any advice, example or solutions.
Thanks
O'Neil