@SuperBuilder
When we had:
@SuperBuilder
public class Organization extends BaseEntity { ... }
MapStruct generated the Organization
like this internally:
Organization.builder()
.createdAt(...) // works even if there's no public setter!
.name(...)
.build();
✅ This works because @SuperBuilder
gives MapStruct full control to set values via builder methods, including private fields like createdAt
that don’t have public setters.
Even if createdAt
had:
@Setter(AccessLevel.PRIVATE)
it doesn't matter — the builder has access.
@SuperBuilder
When you remove @SuperBuilder
, MapStruct falls back to the default no-args constructor and JavaBeans-style property setters, like:
Organization org = new Organization();
org.setCreatedAt(...); // ← now it fails if setCreatedAt is private
org.setName(...);
⚠️ So if createdAt
or any other field lacks a public setter, MapStruct can’t write to it anymore, hence the error:
Property "createdAt" has no write accessor in Organization.
With @SuperBuilder |
Without @SuperBuilder |
---|---|
Uses Organization.builder() |
Uses new Organization() + setters |
Can set private/final fields | Requires public setters |
Works with immutable patterns | Requires full mutability |