-1

I have a couple of target objects like so:

class TargetParent {
  int id;
  ... other scalar fields
  List<TargetChild> children;
}

class TargetChild {
  ... scalar fields
}

However, in the source object, for complicated reasons the equivalent parent object doesn't have children, instead that comes from a separate map, like so:

class SourceParent {
  int id;
  ... other scalar fields
}

class SourceChild {
  ... scalar fields
}

Map<Integer /* parent.id */, List<SourceChild>> parentToChildrenMap;

What's the cleanest way to write a mapstruct mapper from List<SourceParent> + parentToChildrenMap to List<TargetParent> using mapstruct? Essentially I'd like mapstruct to "zip" the source list and map together into a single target list, without having to write too much mapping code myself.

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.