Scrivio Interview library
ScenarioAdvanced6 min read · updated 12 November 2026

Different services serialise the same Lombok DTOs from a shared library in different JSON shapes, because some apply naming strategies and others rely on Lombok config flags. How would you fix this across 25 services?

The services disagree because the JSON shape is not defined anywhere; it emerges from Lombok-generated accessors, lombok.config flags and each service's own ObjectMapper settings. We fix it by making the contract explicit, in OpenAPI or JSON Schema, and putting it into the shared library itself: explicit @JsonProperty names on fields whose names are part of the contract, a shared Jackson configuration module with the naming strategy, date formats and unknown-property handling, and golden-file contract tests in the library. Then the library is versioned and its changes are communicated like API changes.

Why this question is asked

Shared DTO libraries are supposed to make services agree, so it is surprising when they cause disagreement. But a Java class is not a JSON contract: the same class can produce different JSON in different services. With 25 services, this shows up as consumers that work with one producer and fail with another. Interviewers ask this scenario to see whether we can find the real cause and fix it at the right level. In this answer, we will see where the differences come from, define the contract, put names and configuration into the library, add contract tests, and plan versioning and rollout across 25 services.

1Where the Differences Come From

The JSON for an object is decided by three things together: the class (field names and the accessors Lombok generated from them), the Lombok configuration at compile time, and the ObjectMapper configuration at run time. The shared library only controls the first two, and even those can differ: lombok.config is read from the source tree being compiled, so if the DTO source is copied or compiled in different builds, settings such as lombok.accessors.fluent or lombok.accessors.prefix change the generated method names and therefore the JSON names.

Run-time settings vary even more. One service sets PropertyNamingStrategies.SNAKE_CASE so orderId becomes order_id. Another writes dates as numbers because WRITE_DATES_AS_TIMESTAMPS is on; another writes ISO strings. One includes nulls, another omits them with spring.jackson.default-property-inclusion=non_null. The same OrderDto then has four shapes.

Java
// Same class, two services
// Service A (spring.jackson.property-naming-strategy=SNAKE_CASE, dates as text):
// {"order_id":"A1","placed_at":"2026-11-05T10:15:00Z","note":null}
// Service B (defaults, nulls omitted, dates as numbers):
// {"orderId":"A1","placedAt":1793873700000}
Where each difference comes from
DifferenceSet inOwned by
camelCase vs snake_case namesObjectMapper naming strategyeach service
Dates as numbers vs ISO textWRITE_DATES_AS_TIMESTAMPSeach service
Nulls written or omitteddefault property inclusioneach service
Accessor names, boolean namesLombok and lombok.configthe build that compiles the DTO
Unknown fields fail or ignoredFAIL_ON_UNKNOWN_PROPERTIESeach service
Most of the shape is decided outside the shared library.

2Define the Contract Explicitly

The fix starts with a decision: the JSON contract is a document, not a side effect. We write it as OpenAPI for HTTP APIs or JSON Schema for messages, choosing one naming style (say camelCase), one date format (ISO 8601 strings in UTC), whether nulls are written, and how unknown fields are handled. That document is the reference when services disagree, and it is what other teams, including non-Java ones, read.

Then the library is made to match the document, independently of any service's settings. That is the important shift: the DTO library owns the shape of its DTOs.

3Put Names and Configuration Into the Library

For fields whose names are part of the contract, we put explicit @JsonProperty names on them. An explicit name is not changed by a naming strategy, so OrderDto writes orderId whether the service uses camelCase or snake_case. For dates and formats, @JsonFormat on the field fixes the representation, and @JsonInclude on the class fixes the null handling.

Java
@Value
@Builder
@Jacksonized
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OrderDto {
@JsonProperty("orderId") String orderId;
@JsonProperty("placedAt") Instant placedAt; // ISO text, see the shared module
@JsonProperty("note") String note;
}

For settings that cannot be expressed per field, the library ships a small Jackson configuration module, for example a Spring Boot auto-configuration that provides a Jackson2ObjectMapperBuilderCustomizer (or the equivalent for Jackson 3 in Spring Boot 4; check your version). It registers the JavaTimeModule, turns off timestamps for dates and sets the agreed handling of unknown properties. Services that use the library get the configuration automatically, and a service that really needs a different global setting can still not break the DTOs, because their names are explicit.

4Golden-File Contract Tests in the Library

The library proves its contract with tests that serialise sample objects and compare the result with golden JSON files checked into the repository, and that deserialise the golden files back. The test uses a deliberately unfriendly ObjectMapper, for example one with SNAKE_CASE, to show that the explicit names hold.

Java
@ParameterizedTest
@MethodSource("mappers") // the shared configuration, plus a SNAKE_CASE mapper
void orderMatchesGoldenFile(ObjectMapper mapper) throws Exception {
OrderDto sample = OrderDto.builder().orderId("A1").placedAt(Instant.parse("2026-11-05T10:15:00Z")).build();
String expected = Files.readString(Path.of("src/test/resources/golden/order.json"));
JSONAssert.assertEquals(expected, mapper.writeValueAsString(sample), true);
assertEquals(sample, mapper.readValue(expected, OrderDto.class));
}
// golden/order.json: {"orderId":"A1","placedAt":"2026-11-05T10:15:00Z"}

Any change that alters the JSON, whether from a renamed field, a Lombok upgrade or a new annotation, now fails a test in the library, before it reaches 25 services. Consumer-driven contract tests, such as Spring Cloud Contract or Pact, can add the consumers' view on top.

5Versioning and Rolling Out Across 25 Services

The library is versioned with semantic versioning, and any change to a golden file is treated as an API change: compatible additions in minor versions, renames and removals only in major versions after deprecation, with release notes that show the JSON before and after.

For the rollout, we first inventory which shape each service produces today, because some consumers may depend on the wrong shape. Then services move to the new library version in an order that keeps consumers working: where shapes differ, producers can temporarily accept both names on input with @JsonAlias while consumers switch. A dashboard of services and their library version shows progress until all 25 are on it.

Step throughRolling out a consistent DTO library
  1. Write the contractOpenAPI or JSON Schema
  2. Explicit names and formats in the DTOs@JsonProperty, @JsonFormat, @JsonInclude
  3. Ship the shared Jackson moduleauto-configured in every service
  4. Golden-file tests in the libraryrun with an unfriendly mapper too
  5. Inventory current shapesfind consumers of the wrong shape
  6. Upgrade services in order@JsonAlias for a transition period

6 steps in order. Play them, or step through them one at a time.

6Follow-up questions

Why not just tell all services to use the same ObjectMapper settings?

Because it relies on 25 teams keeping their configuration identical forever, and some have good reasons for other global settings. Putting the contract into the DTOs and the shared module makes the shape correct regardless of each service's choices.

Is @JsonProperty on every field too verbose?

It is more text, but each name then states the contract in the code, and it survives refactorings and naming strategies. For DTOs that cross service boundaries, that explicitness is the point.

Should the DTO library depend on Lombok at all?

It can, but generated accessors must not decide the contract. With explicit annotations and golden tests, Lombok is only a convenience; if it changes its output, the tests catch it.

7Conclusion

In this answer, we traced the different JSON shapes to settings outside the shared library: per-service ObjectMapper configuration and Lombok-generated accessor names. We fixed it by defining the contract in OpenAPI or JSON Schema, putting explicit @JsonProperty names, formats and inclusion rules into the DTOs, shipping a shared Jackson configuration module with the library, proving the shape with golden-file tests, and versioning the library and rolling it out like an API change.

What to say in the interviewAbout 80 seconds aloud

Open with

The root cause is that nobody owns the JSON shape. It comes out of Lombok's generated accessors, lombok.config flags in whatever build compiles the DTOs, and each service's ObjectMapper settings: one uses snake_case, one writes dates as numbers, one omits nulls.

Then, if they want more

So the same class has several shapes. I would first write the contract down, OpenAPI for HTTP or JSON Schema for messages, with one naming style, ISO dates and clear null and unknown-field rules. Then I make the library enforce it.

Fields whose names are part of the contract get explicit @JsonProperty names, which naming strategies do not change, plus @JsonFormat and @JsonInclude where needed. For global settings the library ships a small Jackson configuration module, an auto-configured customizer, so every service gets the same date handling and modules.

Then golden-file contract tests in the library: serialise sample objects and compare with checked-in JSON, also with a deliberately different mapper like snake_case, and deserialise the files back. Any change to the shape fails there, not in production. Finally, the library is versioned semantically and JSON changes are treated as API changes with release notes.

For the rollout across 25 services, I would inventory current shapes, use @JsonAlias to accept both names during the transition, and track which services have upgraded.

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 "Different services serialise the same Lombok DTOs from a shared library in different...": https://scrivio-interview-library.netlify.app/java/lombok/3fd4b05193/