Quick revision
The short answer
The main risk is that accessors change from getName() to name(), and everything that finds properties by JavaBean naming, such as Thymeleaf expressions, MapStruct expressions, reflection and hand-written mapping code, may stop finding them. Before the change we check how Jackson, Thymeleaf and MapStruct handle records in our versions, find builders and inheritance that records cannot express, and add contract tests for JSON and template output. Then we convert in small batches, letting the tests prove that nothing visible changed.
What to remember
In this answer, we saw that moving 300 @Value DTOs to records changes accessor names, toString output and what the classes can extend. The compiler catches Java callers, but templates, MapStruct expressions, JSON annotations and reflection-based code need explicit checks against our library versions. Builders can stay through Lombok's @Builder on records, inheritance becomes interfaces or composition, and the whole change runs in small batches guarded by JSON and template contract tests that pass before and after.
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 main risk is that accessors change from getName() to name(), and everything that finds properties by JavaBean naming, such as Thymeleaf expressions, MapStruct expressions, reflection and hand-written mapping code, may stop finding them. Before the change we check how Jackson, Thymeleaf and MapStruct handle records in our versions, find builders and inheritance that records cannot express, and add contract tests for JSON and template output. Then we convert in small batches, letting the tests prove that nothing visible changed.
Why this question is asked
Replacing Lombok @Value classes with records sounds like a mechanical refactoring, and for the Java compiler it mostly is: every getName() call that no longer exists becomes a compile error we can fix. The danger is in the places the compiler cannot see, such as templates, JSON field names, string expressions in mappers and reflection. Interviewers ask this scenario to see whether we can plan a wide change safely. In this answer, we will list what actually changes when a class becomes a record, look at Jackson, Thymeleaf and MapStruct in turn, deal with builders and inheritance, and then plan an incremental rollout with contract tests.
1What Changes When a @Value Class Becomes a Record
A Lombok @Value class and a record both produce an immutable class with equals, hashCode and toString, so most behaviour stays the same. Three things change. The accessor name changes from getTotal() to total(). The toString format changes from OrderDto(id=1, total=9.50) to OrderDto[id=1, total=9.50], which matters if any log parser, test or, worse, production code reads it. And the class can no longer extend another class or carry Lombok extras unless we add them back.
With 300 DTOs, the first job is an inventory. For each DTO we want to know where it is serialised to JSON, which templates render it, which mappers read or write it, whether it uses @Builder or @With, and whether it extends a base class. A few searches across the code and the templates folder give most of this, and the list tells us which DTOs are easy and which need care.
Notice the split in that last part. Java callers fail loudly at compile time, which is the safe kind of failure. Template expressions, JSON names and strings inside annotations fail only at runtime, or worse, silently render an empty value. Those are what our checks must cover.
2Checking Jackson Serialisation
Jackson supports records directly in current versions: it serialises each component as a property and deserialises through the canonical constructor. The JSON field names come from the component names, which match the old property names (getTotal() gave total), so plain DTOs usually produce identical JSON.
The edge cases are annotations and naming. On a Lombok class, @JsonProperty or @JsonIgnore might sit on a field, and Lombok may or may not copy it to the getter depending on configuration. On a record we put annotations on the component, and Jackson must apply them to the accessor and the constructor parameter. Naming strategies such as snake_case, custom deserialisers and @JsonCreator factory methods have had record-related bugs in some Jackson versions, so we check our version's release notes and test them. Old Lombok workarounds, such as @Jacksonized or @JsonDeserialize(builder = ...), can be removed because the constructor now does the job.
3Checking Thymeleaf Templates and Reflection
In a Spring application, Thymeleaf evaluates expressions such as ${order.total} with SpEL, Spring's expression language. SpEL resolves a property by looking for getTotal(), isTotal() or a field. Recent Spring versions also resolve record-style accessors such as total(), but this depends on the version and the exact expression, so we check our versions and test real pages. Writing ${order.total()} calls the method explicitly and works either way.
The worst case here is silent: a property that cannot be resolved might throw an error, but a template written with a safe navigation operator or a default value may just render nothing. That is why we compare the rendered output, not only the absence of exceptions. The same question applies to any other reflection-based code that relies on JavaBean conventions: Spring's BeanUtils.copyProperties, reporting libraries, CSV writers that use introspection, and our own utilities. A record has no setters and no getX() methods, so tools built on java.beans.Introspector may see no properties at all.
4Checking MapStruct Mappers
MapStruct, a code generator for mapping between objects, supports records as both source and target in its current versions. It reads components through their accessors and builds a record target through the canonical constructor. Mappings by property name, such as @Mapping(target = "total", source = "amount"), keep working because the property names did not change.
Three things break. Java expressions written as strings, such as expression = "java(src.getTotal().setScale(2))", are only compiled inside the generated mapper and will fail there after the change. Mappers that relied on the Lombok builder of the target may behave differently once the target is a record, because MapStruct prefers a builder if it finds one; if we keep @Builder on the record, it may still use it. And the annotation processor order, Lombok before MapStruct with the lombok-mapstruct-binding artifact, still matters for every DTO that keeps Lombok. Looking at the generated mapper sources before and after is the quickest way to see what changed.
5Replacing Builders and Inheritance
Builders are often used heavily in tests: OrderDto.builder().id("o1").total(TEN).build(). Lombok supports @Builder and @With on records, so the simplest route is to keep them on the record, and the call sites do not change. Where a DTO has only two or three fields, a static factory method or the constructor itself is clearer, and we can drop the builder.
Inheritance needs a design change. Records cannot extend a class, so a BaseDto with id and createdAt must become an interface that each record implements, or a small record that the others contain.
The interface route keeps the JSON exactly the same, because each record still has id and createdAt as its own components. Composition is often cleaner in Java, but it nests the JSON unless we flatten it, and support for unwrapping on records depends on the Jackson version, so we check it. Code that used instanceof BaseDto switches to instanceof Audited.
6Converting Incrementally With Contract Tests
Before touching any DTO, we freeze its visible behaviour in contract tests: a JSON test that serialises a sample instance and compares it with a stored JSON file, a test that deserialises that file back, and a rendering test for each template that compares the HTML with a stored snapshot. These tests pass on the Lombok version first, which proves they describe today's behaviour.
Then we convert in batches, for example 20 DTOs per pull request, grouped by module. Tools such as OpenRewrite have recipes that convert simple @Value classes to records (check the recipe name for your version), which saves typing but not checking. Each batch must keep every contract test green and every generated mapper compiling.
- Pick 20 DTOs from one modulesimple ones first, inheritance last
- Add JSON and template snapshot teststhey must pass on the Lombok version
- Convert to recordskeep
@Builderor@Withwhere call sites need them - Fix compile errors
getX()calls in Java code - All snapshots identical?YesMerge the batchNoFix templates, mappers or annotations
- Repeat for the next batch
6 steps in order. Play them, or step through them one at a time.
Batching keeps each review small, makes a failing batch easy to revert, and lets other teams keep merging their own changes while the migration runs. A 300-DTO change in one pull request would conflict with everyone else's work and would be impossible to review properly.
7Follow-up questions
Why not just do all 300 DTOs at once with a refactoring tool?
The tool handles the Java side, but the risk is outside Java: templates, string expressions and JSON annotations. A single huge change makes it impossible to tell which DTO caused a broken page, conflicts with every other branch, and is hard to roll back. Small batches with snapshot tests give the same end result with a clear signal at every step.
Do we have to remove Lombok completely?
No. The goal is simpler, standard code, not zero Lombok. DTOs with many optional fields can stay as records with Lombok @Builder, and JPA entities will keep Lombok getters and setters because they can never be records. We can stop using @Value for new code and let the rest follow.
8Conclusion
In this answer, we saw that moving 300 @Value DTOs to records changes accessor names, toString output and what the classes can extend. The compiler catches Java callers, but templates, MapStruct expressions, JSON annotations and reflection-based code need explicit checks against our library versions. Builders can stay through Lombok's @Builder on records, inheritance becomes interfaces or composition, and the whole change runs in small batches guarded by JSON and template contract tests that pass before and after.
Open with
First I would inventory the DTOs: which are serialised to JSON, which templates render them, which MapStruct mappers use them, which use @Builder or @With, and which extend a base class.
Then, if they want more
The key change is that getName() becomes name(). The compiler finds Java callers, but not Thymeleaf expressions, string expressions in MapStruct mappings, or reflection that relies on JavaBean getters, so I would check each library's record support in our versions.
Jackson handles records directly, and the property names stay the same, but I would check @JsonProperty placement, naming strategies and custom deserialisers. Builders can stay, because Lombok supports @Builder on records, or I replace them with static factories for small DTOs. Inheritance has to become interfaces with accessor methods, which keeps the JSON the same, or composition.
Before changing anything I would add contract tests that snapshot the JSON and the rendered templates and pass on the Lombok version. Then I would convert in batches of about twenty DTOs per pull request, possibly with an OpenRewrite recipe, and merge a batch only when every snapshot is identical and the generated mappers compile.
About this answer
- Last updated
- 12 November 2026
- 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 "A team wants to replace all Lombok @Value DTOs with records in a service with 300 DTOs...": https://scrivio-interview-library.netlify.app/java/lombok/cc3690fc84/