Scrivio Interview library
ScenarioAdvanced6 min read · updated 12 November 2026

Your platform team wants a standard for API DTOs across fifty Spring Boot services, choosing between records, Lombok classes and hand-written classes. What do you decide and how do you roll it out?

I would standardise on records for new API DTOs across the fifty services: they are a language feature, need no annotation processor, are final and immutable, and work with every Jackson and Bean Validation version that current Spring Boot manages. PATCH requests need an explicit design because a record cannot tell a missing field from a null. Lombok stays allowed for mutable classes and entities, existing DTOs are converted only when touched, JSON contracts are checked by tests during each conversion, and the standard documents boolean component naming and nullability rules.

Why this question is asked

A platform team choosing a DTO standard is not picking a syntax; it is choosing what fifty services will look like to the people who maintain them for the next decade. Interviewers ask this scenario to see whether we can weigh technical facts against migration cost and turn a decision into something teams will actually follow. In this answer, we will compare the three options on the points that matter, decide, handle the PATCH problem, write the conventions the standard needs, and plan the rollout.

1Comparing the Three Options

A hand-written class gives full control but costs boilerplate, and boilerplate drifts: an added field missing from equals or toString is a common review finding. Lombok removes the boilerplate with annotations such as @Value or @Data, processed by an annotation processor that plugs into compiler internals. That works well, but it adds a build-time dependency that must release a compatible version for each new JDK, and it can surprise readers, because the code they read is not the code that runs.

Records are part of the language since Java 16. They need no plugin, every IDE and tool understands them, and they carry a precise meaning: a final, immutable carrier whose state is its API. Jackson binds them through the canonical constructor since 2.12, Hibernate Validator validates constraints on their components, and springdoc generates OpenAPI schemas from them. For request and response DTOs, which are data and nothing else, that meaning is exactly right.

API DTO options for 50 services
CriterionRecordsLombokHand-written
Build dependencyNoneAnnotation processor per JDKNone
ImmutabilityFinal, shallowly immutable@Value yes, @Data noAs written
BoilerplateNoneNoneHigh, drifts
Jackson / validationSince 2.12 / yesYesYes
Partial update (PATCH)Needs explicit designSetters make it easyAs written
Readers see what runsYesNo, generatedYes
Records win for request and response DTOs; PATCH is the one place that needs extra design.

2The Decision

I would decide: records are the standard for all new request and response DTOs, events and messages. Lombok remains allowed, but only for mutable classes such as JPA entities and for builders of very large types, and it is not used for new DTOs. Hand-written classes are allowed when a DTO genuinely needs something a record cannot give, which in practice is rare. The reasons I would give the teams are the ones above: no compiler plugin to keep current across JDK upgrades, immutability by default, and code that reads exactly as it runs.

3Designing PATCH Requests

The one real gap is partial updates. A PATCH body such as {"nickname": null} means clear the nickname, while {} means leave it alone. A record with a String nickname component receives null in both cases, so the service cannot tell them apart. With setter-based classes, teams often tracked which setters were called, which is fragile anyway.

Java
// Option 1: a small tri-state wrapper per field
public record UpdateProfile(Patch<String> nickname, Patch<String> phone) {}
public sealed interface Patch<T> {
record Absent<T>() implements Patch<T> {}
record Value<T>(T value) implements Patch<T> {} // value may be null: clear the field
}
// needs a small Jackson deserializer (or a module) so that a missing field becomes Absent
// Option 2: JSON Merge Patch (RFC 7396), applied to the current state
@PatchMapping(path = "/profiles/{id}", consumes = "application/merge-patch+json")
ProfileResponse patch(@PathVariable String id, @RequestBody JsonNode patch) { ... }

Either way, the standard should name one approach for the whole platform, with a shared library or example, so fifty services do not invent five answers. Libraries such as jackson-databind-nullable offer a ready-made tri-state type; whether to depend on one is a choice the platform team should make once.

4Conventions the Standard Must Write Down

Records remove most choices, but two remain and both have caused production issues. The first is boolean naming. A component called isActive produces the JSON property isActive, while the old getter isActive() on a class produced active. The rule is to name boolean components without the prefix, active, enabled, verified, so the accessor and the JSON both read naturally.

The second is nullability. The standard should say which components may be null, how that is expressed, and what the JSON looks like. A common choice is that components are non-null by default, optional fields are marked with JSpecify @Nullable, compact constructors call Objects.requireNonNull for required references, collections are never null but empty, copied with List.copyOf, and Jackson is configured once, in a shared starter, to omit or include nulls consistently. Optional is not used as a component type, because it is designed for return values.

5Rolling It Out

The rollout starts with the platform's own assets: the service template and the shared starter produce records, the API guidelines document the conventions with examples, and an ArchUnit rule can check that classes in api packages are records. New endpoints follow the standard immediately. Existing DTOs keep their current form until a team touches them for another reason, because converting stable code for its own sake costs review time and risks contract changes.

When a DTO is converted, the change must not alter the JSON. So every conversion comes with a serialization test that compares the output with the previous JSON, using @JsonTest or a stored sample, and services with external consumers also run their consumer contract tests. Comparing the generated OpenAPI documents before and after the change is a cheap extra safety net. After a year, I would review how many new DTOs follow the standard and which exceptions teams requested, and adjust the guidance from what we learn.

6Follow-up questions

Why not let each team choose?

Because DTOs are where services meet, and shared libraries, code generators and reviewers all work better with one shape. The cost of a single standard is small, and the cost of fifty slightly different conventions shows up in every cross-team review and incident.

What about DTOs generated from OpenAPI specifications?

The generator's output should follow the same rules where it can. Several generators can produce records or immutable models through configuration; check the options of the generator version you use, and set them once in the shared build configuration.

Does Lombok's need to track JDK internals really matter?

It matters at JDK upgrade time. Each new JDK can require a new Lombok release, and fifty services cannot upgrade the JDK until it exists and is adopted. Records remove that dependency from the most common type in an API service.

7Conclusion

In this answer, we compared records, Lombok and hand-written classes for API DTOs, chose records for new DTOs because they need no annotation processor, are immutable and are supported by Jackson and Bean Validation, and kept Lombok for mutable classes and entities. We designed PATCH explicitly with a tri-state type or JSON Merge Patch, wrote down boolean naming and nullability rules, and rolled the standard out through templates and starters, converting existing DTOs only when touched and checking JSON contracts with tests.

What to say in the interviewAbout 90 seconds aloud

Open with

I would standardise on records for new request and response DTOs, events and messages. The reasons are that records are a language feature, so there is no annotation processor that has to keep up with every JDK release, they are final and immutable, which is what a DTO should be, and Jackson since 2.12 and Hibernate Validator both support them, so they work with every Spring Boot version we would run.

Then, if they want more

Lombok stays allowed for mutable classes, mainly JPA entities, and hand-written classes are fine when a record really cannot do the job.

The one gap is PATCH: a record cannot tell a missing field from an explicit null, so the standard picks one approach, either a small tri-state type with a shared Jackson deserializer or JSON Merge Patch on a JsonNode, and the platform provides it.

I would also document two conventions that have caused real breakages: boolean components are named without the is prefix, because a record component isActive becomes isActive in JSON, and nullability rules, with non-null by default, @Nullable for optional fields, empty collections instead of null.

For the rollout, templates and the shared starter produce records from day one, an ArchUnit rule checks api packages, existing DTOs are converted only when teams touch them, and every conversion includes a JSON contract test against the previous output.

About this answer

Last updated
12 November 2026
Versions it names
Java 16
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. 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 "Your platform team wants a standard for API DTOs across fifty Spring Boot services...": https://scrivio-interview-library.netlify.app/java/records/a324b428ea/