Quick revision
The short answer
The class has no no-args constructor and no setters, so Jackson does not know how to create it. The first approach is to add @Jacksonized next to @Builder, which makes Jackson build the object through the generated builder and configures the builder's method names for it. The second is to give Jackson a creator: the all-args constructor marked @JsonCreator through @AllArgsConstructor(onConstructor_ = @JsonCreator), with parameter names coming from @JsonProperty or from compiling with -parameters and the ParameterNamesModule that Spring Boot registers; lombok.anyConstructor.addConstructorProperties = true is a third option.
What to remember
In this answer, we saw why an immutable @Value @Builder class cannot be read by Jackson as written: it has no no-args constructor, no setters and no recognised creator. We made it work with @Jacksonized, which points Jackson at the Lombok builder and fixes the method prefix, and with an all-args constructor marked @JsonCreator whose parameter names come from -parameters and the ParameterNamesModule or from @JsonProperty. We also saw the @ConstructorProperties config option, the boolean naming trap, and why a record is often the simplest choice.
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.
The class has no no-args constructor and no setters, so Jackson does not know how to create it. The first approach is to add @Jacksonized next to @Builder, which makes Jackson build the object through the generated builder and configures the builder's method names for it. The second is to give Jackson a creator: the all-args constructor marked @JsonCreator through @AllArgsConstructor(onConstructor_ = @JsonCreator), with parameter names coming from @JsonProperty or from compiling with -parameters and the ParameterNamesModule that Spring Boot registers; lombok.anyConstructor.addConstructorProperties = true is a third option.
Why this question is asked
Immutable DTOs are a good habit: once created, they cannot be changed by accident as they pass through the code. But Jackson's default way of reading JSON is to create an empty object and set its fields one by one, which an immutable class does not allow. Interviewers give this coding task to see whether we know how Jackson creates objects and how Lombok can work with that. In this answer, we will recap why the class fails as written, then build two working approaches, look at a third configuration option, check a boolean naming trap, and compare everything with a record.
1Why the Class Fails as Written
@Value makes the class final and its fields private final, and generates getters, toString, equals and hashCode. Since @Builder is also present, the class gets a package-private all-args constructor and a builder, and no no-args constructor and no setters.
| Way | What Jackson needs | Fits an immutable class? |
|---|---|---|
| No-args constructor + setters | a visible no-args constructor | no: needs mutable fields |
| Creator constructor | @JsonCreator and known parameter names | yes |
| Builder | @JsonDeserialize(builder = ...) and matching method names | yes |
Jackson can create an object in three ways: a no-args constructor followed by setters or field writes, a creator (a constructor or static factory marked @JsonCreator, whose parameters are matched to JSON properties), or a builder it has been told about. This class offers none of them in a form Jackson recognises, so it gives up. Both approaches below give Jackson one of these ways while keeping the class immutable.
2Approach 1: @Jacksonized and the Generated Builder
Lombok's @Jacksonized annotation, available since Lombok 1.18.14, is placed next to @Builder. It adds @JsonDeserialize(builder = Address.AddressBuilder.class) to the class and @JsonPOJOBuilder(withPrefix = "") to the builder. That second part matters: by default Jackson expects builder methods named withStreet(...), while Lombok generates street(...). @Jacksonized tells Jackson to use the names as they are. It also copies Jackson annotations from the fields to the builder methods.
6 messages in order. Play them, or step through them one at a time.
Notice that serialisation needed no help: Jackson writes JSON from the getters, which @Value already generates. Only reading needed the builder. If you are on Jackson 3 with Spring Boot 4, check that your Lombok version supports it with @Jacksonized.
3Approach 2: A Creator Constructor
Instead of the builder, we can let Jackson call the all-args constructor directly. We ask Lombok to put @JsonCreator on the generated constructor with the onConstructor_ parameter. Jackson then needs to know which JSON property goes to which parameter. Java does not keep parameter names in class files unless we compile with -parameters, so either we compile that way and register Jackson's ParameterNamesModule, which Spring Boot does for us, or we name each parameter with @JsonProperty.
Notice that @Builder still works, because it uses the explicit all-args constructor. If we cannot rely on -parameters, the robust option is to write the constructor by hand with @JsonCreator and @JsonProperty("street") on each parameter. Explicit names also protect the JSON contract from someone renaming a parameter.
4A Third Option: @ConstructorProperties From lombok.config
Lombok can add the standard @java.beans.ConstructorProperties annotation to every constructor it generates, listing the parameter names. Jackson treats a constructor with that annotation as a creator.
This was Lombok's default before version 1.16.20, and its removal from the default broke many projects that had relied on it without knowing. Whether Jackson uses it can depend on your Jackson version and settings, so check it with a test. It is project-wide, which makes it convenient but implicit; the two approaches above are visible in the class itself.
5Watch the Boolean Getters
Jackson derives property names from getters. For a primitive boolean field active, Lombok generates isActive(), and Jackson names the property active, as expected. But for a field called isActive, Lombok also generates isActive() and setActive(), so the JSON property becomes active, not isActive, and a Boolean wrapper field gets getIsActive() instead. When the class has booleans, a test should check the exact JSON shape.
6Records Are Often Simpler
Since Jackson 2.12, records are supported directly: Jackson uses the canonical constructor and the component names, with no annotations and no Lombok. For a pure data carrier like Address, a record is usually the simplest answer.
Lombok still helps when we want a builder for a class with many optional fields. Lombok's @Builder can also be put on a record, and with @Jacksonized the builder is then used for reading.
7Follow-up questions
Which approach would you choose?
For a Lombok class with a builder, @Jacksonized, because it is explicit in the class, keeps the class immutable and uses the builder that already exists. For a simple carrier with two fields, a record. The creator constructor is a good choice when we cannot use a builder or want explicit @JsonProperty names on a hand-written constructor.
Why does Jackson expect withStreet by default?
Jackson's builder support was designed around the common convention of with-prefixed builder methods. @JsonPOJOBuilder lets us change the prefix, and @Jacksonized sets it to the empty string to match Lombok's method names.
Do unknown JSON properties break these approaches?
Only if FAIL_ON_UNKNOWN_PROPERTIES is on. It is on by default in a plain ObjectMapper but off in the one Spring Boot configures. For contract safety, decide explicitly, for example with @JsonIgnoreProperties(ignoreUnknown = true) on the DTO.
8Conclusion
In this answer, we saw why an immutable @Value @Builder class cannot be read by Jackson as written: it has no no-args constructor, no setters and no recognised creator. We made it work with @Jacksonized, which points Jackson at the Lombok builder and fixes the method prefix, and with an all-args constructor marked @JsonCreator whose parameter names come from -parameters and the ParameterNamesModule or from @JsonProperty. We also saw the @ConstructorProperties config option, the boolean naming trap, and why a record is often the simplest choice.
Open with
As written, Jackson has no way to create the object: @Value gives final fields and no setters, @Builder generates a package-private all-args constructor and a builder, and there is no no-args constructor, so Jackson reports no Creators.
Then, if they want more
My first approach is to add @Jacksonized next to @Builder. Since Lombok 1.18.14 it adds @JsonDeserialize with the builder class and @JsonPOJOBuilder with an empty prefix, because Jackson would otherwise expect withStreet rather than street. Jackson then calls builder, street, city and build, and the class stays immutable. Serialisation already works from the getters.
My second approach is a creator: @AllArgsConstructor(onConstructor_ = @JsonCreator), so the constructor is public and marked as a creator, and @Builder still uses it. Jackson needs the parameter names, which come from compiling with -parameters plus the ParameterNamesModule; Spring Boot sets both up. Without that, I would hand-write the constructor with @JsonProperty on each parameter.
A third, project-wide option is lombok.anyConstructor.addConstructorProperties = true, which adds @ConstructorProperties for Jackson to use. I would also watch boolean fields, since a field named isActive becomes the property active. And honestly, for a simple carrier like Address, a record works with Jackson out of the box and is often the better answer.
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 "Make this immutable Lombok class deserialise with Jackson:": https://scrivio-interview-library.netlify.app/java/lombok/bf6ef5f4f9/