0

I want to map the fields of two java objects based on condition like below.

if(sourceObject.getField1() != null && targetObject.getField1() == null){
     targetObject.setFields1(sourceObject.getField1())

}

I am using mapstruct @MappingTarget annotation but it is not giving me what I am expecting like above. I have multiple classes/subclasses with a hundred fields. Any suggestions or examples will help.

Cavan P
  • 9
  • 6
VKR
  • 195
  • 4
  • 18
  • How does it look like now? – Filip Dec 20 '20 at 13:21
  • Still I had issue..Do you have any generic solution? – VKR Dec 20 '20 at 15:09
  • In order for me to give you an answer you'll need to share how the generated code looks like right now and how your mapper looks like – Filip Dec 20 '20 at 21:40
  • @VKR Please, can you review this [SO answer](https://stackoverflow.com/questions/65367995/copy-changed-fields-into-an-object-in-java/65369332#65369332) I provided? It is very similar to your problem. I hope it helps. – jccampanero Jan 07 '21 at 19:27

1 Answers1

0

Not a generic solution but if you have to do specific things, you can do it in a @AfterMapping annotated method.

Maneki
  • 307
  • 2
  • 4