How to instruct MapStruct to use Builder without a static method

Viewed 102

I have a simple MapStruct class:

@Mapper
public interface SomeMapper {
    SomeDto map(SomeModel someModel);
    SomeModel map(SomeDto someDto);
}

The problem is, my SomeModel is using a Builder but without a static method, i.e.

class SomeModel {
  public static class Builder {

  }

  // there is no public static Builder builder() method available
}

How do I tell MapStruct that it needs to directly use the new SomeModel.Builder() instead of SomeModel.builder()?

1 Answers

There is no out-of-the-box way for MapStruct to detect that SomeModel.Builder is the builder for SomeModel.

However, you could provide your own BuilderProvider SPI and implement the logic you want. You can read more about that here.

Related