Quick revision
The short answer
@Builder on a class generates a package-private all-args constructor, and as soon as a class has any constructor, Java no longer adds the implicit no-args constructor. Jackson and JPA both need a no-args constructor by default, so deserialisation fails with "no Creators, like default constructor, exist" and Hibernate fails to instantiate the entity. The fix is to add @NoArgsConstructor together with @AllArgsConstructor so @Builder still has its constructor, or to let Jackson use the builder itself with @Jacksonized.
What to remember
In this answer, we saw that @Builder on a class generates an all-args constructor, and because a class with any declared constructor gets no implicit no-args constructor, Jackson and JPA lost the constructor they relied on. We fixed it with @NoArgsConstructor plus @AllArgsConstructor, protected and private for entities, or with @Jacksonized so Jackson builds DTOs through the builder, and we added round-trip tests for every public DTO and a save-and-reload test for entities.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
@Builder on a class generates a package-private all-args constructor, and as soon as a class has any constructor, Java no longer adds the implicit no-args constructor. Jackson and JPA both need a no-args constructor by default, so deserialisation fails with "no Creators, like default constructor, exist" and Hibernate fails to instantiate the entity. The fix is to add @NoArgsConstructor together with @AllArgsConstructor so @Builder still has its constructor, or to let Jackson use the builder itself with @Jacksonized.
Why this question is asked
This error appears the moment someone adds a builder to a class that has worked for months, and it usually shows up far away from the change, in a REST call or a database read. Interviewers ask it because it combines a Java language rule, how Lombok's @Builder works, and what Jackson and JPA need to create objects. In this answer, we will recap how Jackson and JPA create instances, reproduce the failure, see why the default constructor disappeared, go through the fixes, and add tests that catch it.
1A Quick Recap: How Jackson and JPA Create Objects
When Jackson reads JSON into a class, by default it calls the no-args constructor and then sets each property through setters or fields. If there is no no-args constructor, Jackson needs another way: a constructor or factory marked @JsonCreator, or a builder it has been told about. Without one, it gives up.
JPA providers such as Hibernate also create entities with a no-args constructor when they load rows, then fill the fields. The JPA specification requires entities to have a public or protected no-args constructor.
And Java itself has one rule that matters here: the compiler adds an implicit no-args constructor only when a class declares no constructors at all. The class in the question had none, so it silently had one.
2Reproducing the Failure
Here is the DTO before and after the change.
For an entity, the same change produces a Hibernate error saying there is no default constructor for the entity when it is loaded, for example org.hibernate.InstantiationException; the exact class and message depend on your Hibernate version.
3Why the Default Constructor Disappeared
@Builder needs a constructor that takes every field, because build() ends with new OrderDto(id, quantity). If the class has no constructor, Lombok generates that all-args constructor with package-private access. Now the class declares a constructor, even though we did not type it, so the compiler no longer adds the implicit no-args one. The no-args constructor Jackson and Hibernate relied on is gone.
| Version | Constructors in the class file | Jackson | JPA |
|---|---|---|---|
| no Lombok constructors | public OrderDto() (implicit) | works | works |
@Builder added | OrderDto(String, int), package-private | no creator: fails | no default constructor: fails |
@Builder + @NoArgsConstructor + @AllArgsConstructor | OrderDto() and OrderDto(String, int) | works | works |
@Builder + @Jacksonized | all-args only; Jackson uses the builder | works | still fails |
Notice that nothing in our source mentions constructors at all. The change in the class's shape happened inside the generated code, which is why this bug surprises people.
4Fix 1: Add Both Constructors Explicitly
We ask Lombok for both constructors. @Builder then uses the all-args constructor, and Jackson and Hibernate use the no-args one. @Builder needs @AllArgsConstructor here: if we added only @NoArgsConstructor, @Builder would have no all-args constructor to call, and Lombok would not generate one because the class now has a constructor.
For the entity, the protected no-args constructor satisfies JPA while discouraging new OrderEntity() in application code, and the private all-args constructor means the only public way to create one is the builder.
5Fix 2: Let Jackson Use the Builder With @Jacksonized
For immutable DTOs, adding a no-args constructor fights the design. Lombok's @Jacksonized (since 1.18.14) tells Jackson to deserialise through the generated builder. It adds @JsonDeserialize(builder = ...) to the class and configures the builder's method names, which have no "with" prefix, as Jackson expects.
5 messages in order. Play them, or step through them one at a time.
This keeps the class immutable. It helps only Jackson, though; an entity still needs its no-args constructor for JPA. If you are on Jackson 3 with Spring Boot 4, check that your Lombok version supports it with @Jacksonized.
6Tests That Catch It Next Time
The bug reached runtime because nothing exercised the constructor Jackson needs. A small round-trip test for every public DTO catches it at build time, and a Spring Data repository test that saves and reloads an entity catches the JPA case.
7Follow-up questions
Why not just make Lombok keep the implicit constructor?
Because it is a Java rule, not a Lombok choice: once a class declares any constructor, the compiler adds no default one. Lombok's generated constructor counts as declared. So we must ask for the no-args constructor explicitly.
Can Jackson use the all-args constructor instead?
Yes, if it is told how. Marking the constructor @JsonCreator, through @AllArgsConstructor(onConstructor_ = @JsonCreator), and compiling with -parameters so the parameter names are known (Spring Boot's build plugins enable this) lets Jackson call it. The constructor must also be visible to Jackson, so public is simplest.
Is a no-args constructor bad for immutability?
For immutable DTOs, yes, which is why @Jacksonized or a creator constructor is the better route there. For JPA entities it is required anyway, and making it protected limits the damage.
8Conclusion
In this answer, we saw that @Builder on a class generates an all-args constructor, and because a class with any declared constructor gets no implicit no-args constructor, Jackson and JPA lost the constructor they relied on. We fixed it with @NoArgsConstructor plus @AllArgsConstructor, protected and private for entities, or with @Jacksonized so Jackson builds DTOs through the builder, and we added round-trip tests for every public DTO and a save-and-reload test for entities.
Open with
The cause is a Java rule combined with what @Builder generates. Before the change the class had no constructors, so the compiler added an implicit public no-args constructor, and Jackson and Hibernate used it. @Builder needs a constructor taking every field, so on a class without constructors Lombok generates a package-private all-args constructor.
Then, if they want more
Now the class declares a constructor, so the implicit no-args one is gone. Jackson by default calls the no-args constructor and then sets properties, so it fails with no Creators, like default constructor, exist, and Hibernate fails to instantiate the entity. The usual fix is to add @NoArgsConstructor and @AllArgsConstructor next to @Builder.
I need both, because with only the no-args one @Builder has no all-args constructor to call. For an entity I make the no-args constructor protected, which JPA allows, and the all-args one private so only the builder uses it.
For immutable DTOs I prefer @Jacksonized, available since Lombok 1.18.14, which tells Jackson to deserialise through the builder and sets up the builder method names, so the class can stay a @Value. That does not help JPA.
Finally I would add round-trip serialisation tests for every public DTO and a repository test that saves and reloads entities, so this fails in the build instead of in production.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Boot 4
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "After adding @Builder to an existing class that had a no-args constructor used by...": https://scrivio-interview-library.netlify.app/java/lombok/212a59c307/