1

I have a class with the following Lombok annotations.

@Getter
@NoArgsConstructor
@AllArgsConstructor
@Builder(toBuilder = true)
public class classA {
  private String id;
  private String a;
  private String b;
}

I need to add a mapping to update an existing instance of ClassA as following :

@Mapping(target = "id", ignore = true)
ClassA update(ClassA oldA, @MappingTarget ClassA newA);

The generated mapper is the following, fields gets ignored in the generated mapping, because they don't have setters.

@Override
public Main.ClassA update(Main.ClassA oldA, Main.ClassA newA) {
  if ( oldA == null ) {
    return newA;
  }
 
  return newA;
}

I tried to use @BeanMapping(builder = @Builder(buildMethod = "toBuilder")) but it has no effect My goal is to make MapStruct use the toBuilder at the first and then the build method to return back a ClassA object, any tips to make this happen?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Wafa
  • 146
  • 3
  • 9
  • Does this answer your question? [How to instruct Mapstruct to use lombok builder?](https://stackoverflow.com/questions/65955000/how-to-instruct-mapstruct-to-use-lombok-builder) – Luca Basso Ricci Mar 28 '23 at 07:10

0 Answers0