Scrivio Interview library
DebuggingIntermediate5 min read · updated 12 November 2026

After switching a DTO from a class to a record, Jackson output changes field names for a component called isActive, and a client breaks. Explain what to check.

For a class with a boolean isActive() getter, Jackson strips the is prefix and names the property active. For a record, the component and its accessor are both called isActive, and Jackson names record properties after the component, so the JSON property becomes isActive and clients expecting active break. Annotate the component with @JsonProperty("active") to keep the contract, check the Jackson version in use because record naming has changed between releases, and add contract tests on the serialized JSON.

Why this question is asked

Converting a DTO to a record looks like a refactoring with no visible effect, so it often ships without anyone looking at the JSON. Then a mobile client stops showing which accounts are active. Interviewers like this debugging question because the cause sits in a convention most of us use without noticing, the JavaBeans rule for boolean getters, and the fix needs us to understand how Jackson discovers properties for classes and for records. In this answer, we will reproduce the change, see how Jackson names properties in each case, fix the contract, and look at how to catch this before release.

1Reproducing the Change

Here is the DTO before and after the conversion, serialized with the same ObjectMapper.

Java
// Before: a class with a boolean getter
public class AccountDto {
private final String id;
private final boolean isActive;
public AccountDto(String id, boolean isActive) { this.id = id; this.isActive = isActive; }
public String getId() { return id; }
public boolean isActive() { return isActive; }
}
mapper.writeValueAsString(new AccountDto("a1", true)); // {"id":"a1","active":true}
// After: a record with the same field names
public record AccountDto(String id, boolean isActive) {}
mapper.writeValueAsString(new AccountDto("a1", true)); // {"id":"a1","isActive":true}

Same data, same field name in the source, different JSON. Any client that reads active now gets a missing field, which in many languages silently becomes false or null rather than an error.

2How Jackson Names Properties for a Class

For an ordinary class, Jackson finds properties mainly through accessor methods, following the JavaBeans naming rules. A method getId() becomes the property id. For boolean values, the rules also accept an is prefix, so isActive() becomes the property active. The private field called isActive is not visible to Jackson by default, so its name plays no role; the getter decides.

So the old contract, active, was never written down anywhere. It was a side effect of a naming convention applied to a getter.

3How Jackson Names Properties for a Record

A record has no getters in the JavaBeans sense. Its accessor is named exactly like its component, so the component isActive gets an accessor isActive(), not isIsActive() and not getActive(). Jackson's record support, available since 2.12, takes property names from the record components themselves, which it reads through Class.getRecordComponents(), and it binds JSON back through the canonical constructor using the same names. The component is called isActive, so the property is isActive.

Where the JSON name comes from
TypeSource of the nameJSON property
Class with isActive() gettergetter, is prefix removedactive
Record with component isActivecomponent nameisActive
Record with component activecomponent nameactive
Record with @JsonProperty("active") isActiveannotationactive
Records take names from components, classes from getters.

A word of caution about versions: Jackson's handling of records, and in particular of accessors that look like is-getters, has changed between 2.x releases, and some releases produced both properties or used the getter-style name. Spring Boot 4 also moves to Jackson 3 by default. So before deciding what the output is, check the exact Jackson version on the classpath, for example with mvn dependency:tree, and test it rather than relying on memory.

4Fixing the Contract

The first fix keeps the record as it is and states the JSON name explicitly. An annotation placed on a record component is propagated by the compiler to the field, the accessor and the canonical constructor parameter, wherever the annotation type allows it, and @JsonProperty allows all three. So one annotation fixes both serialization and deserialization.

Java
public record AccountDto(String id, @JsonProperty("active") boolean isActive) {}
mapper.writeValueAsString(new AccountDto("a1", true)); // {"id":"a1","active":true}
mapper.readValue("{\"id\":\"a1\",\"active\":true}", AccountDto.class); // AccountDto[id=a1, isActive=true]

The second fix is to rename the component to active. The JSON becomes active again and the accessor becomes active(), which reads naturally in Java too. This is the better long-term choice for new types, but renaming changes the Java API, so callers of isActive() must be updated. Whichever we pick, the point is that the JSON contract is now explicit in the code instead of being derived from a naming convention.

5Catching It Before Release

The real lesson is that the JSON shape is an API, and a refactoring that does not change Java callers can still change it. A contract test pins the serialized form. In Spring Boot, a @JsonTest slice with JacksonTester, or a plain test that serializes the DTO with the application's ObjectMapper and compares against a stored JSON file, runs in milliseconds.

Java
@JsonTest
class AccountDtoJsonTest {
@Autowired JacksonTester<AccountDto> json;
@Test
void keepsTheContract() throws Exception {
assertThat(json.write(new AccountDto("a1", true)))
.isEqualToJson("{\"id\":\"a1\",\"active\":true}"); // fails on {"isActive":true}
}
}

For APIs consumed by other teams, consumer-driven contract tests, for example with Spring Cloud Contract or Pact, catch the same change from the client's side. Comparing the generated OpenAPI document between versions is another cheap check, because a renamed property shows up as a removed and an added field.

6Follow-up questions

Could we fix it globally with a naming strategy instead?

Not cleanly. A PropertyNamingStrategy transforms all names, and there is no standard strategy that strips is only from boolean record components. A custom one would surprise the next developer. An explicit annotation on the few affected components, or renaming them, is clearer.

Does the same issue affect deserialization from old clients?

Yes. Clients that send active would have the value ignored, or rejected if FAIL_ON_UNKNOWN_PROPERTIES is enabled, because the record expects isActive. @JsonProperty fixes both directions, since it is propagated to the constructor parameter as well.

How should we name boolean components in records from now on?

Without the is prefix: active, enabled, verified. The accessor then reads as account.active(), and the JSON name matches the component, so there is nothing to translate.

7Conclusion

In this answer, we saw that a class with an isActive() getter produces the JSON property active because Jackson applies the JavaBeans is-prefix rule, while a record with a component named isActive produces isActive because Jackson takes record property names from the components. We restored the contract with @JsonProperty("active") on the component, which also covers deserialization, noted that renaming the component is the cleaner long-term fix, stressed checking the Jackson version, and added contract tests on the serialized JSON.

What to say in the interviewAbout 90 seconds aloud

Open with

The first thing I would check is how the name was derived before and after. For the old class, Jackson discovered properties through getters using the JavaBeans rules, and for a boolean the getter isActive() means the property active.

Then, if they want more

The private field name did not matter. When the DTO became a record, the component is called isActive, and its accessor is also called isActive. Jackson's record support, since 2.12, takes property names from the record components and binds back through the canonical constructor, so the JSON now says isActive.

The client reads active, gets nothing, and probably treats it as false. To fix it without changing the Java API, I would put @JsonProperty("active") on the component. Annotations on record components are propagated to the field, accessor and constructor parameter, so that fixes serialization and deserialization.

For new code I would rather name boolean components without the is prefix, active, so the accessor is active() and the JSON matches. I would also check the exact Jackson version in use, because record handling of is-style accessors has changed between releases, and Spring Boot 4 moves to Jackson 3.

Then, to stop this happening again, I would add contract tests on the serialized JSON, a @JsonTest with JacksonTester comparing against expected JSON, or consumer-driven contracts for external clients.

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 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 "After switching a DTO from a class to a record, Jackson output changes field names for a...": https://scrivio-interview-library.netlify.app/java/records/d943ab8aac/