Scrivio Interview library
ScenarioAdvanced6 min read · updated 12 November 2026

A shared client library uses Gson with 30 custom type adapters, and you are migrating it to Jackson. How would you plan and verify the migration?

We first inventory all 30 adapters and record the JSON each one produces as golden test files, before touching any code. Then we map each adapter to its Jackson equivalent, a serializer and deserializer, a mix-in, or @JsonCreator and @JsonValue, and configure Jackson to match Gson's defaults, since Gson reads fields and omits nulls while Jackson reads getters and includes nulls. We verify by running both libraries side by side over recorded production payloads and diffing the results, and we release the result as a new major version with a migration note while the old version keeps receiving patches for a while.

Why this question is asked

A shared client library is a multiplier. Thirty adapters encode thirty small decisions about how dates, money, enums and polymorphic types look on the wire, and every service that depends on the library inherits them. A migration that changes even one of those decisions silently breaks clients in places nobody is watching. Interviewers ask this scenario to see whether we treat the migration as a contract-preserving change with evidence, rather than a search and replace. In this answer, we will build the safety net first, map the adapters, line up the defaults, verify with real payloads, and plan the release so consumers can move at their own pace.

1Inventory and Golden Tests Before Any Change

We start by listing every adapter, factory, serializer and deserializer registered in the library, the type each handles, and an example of the JSON it produces and accepts. Then, still on the Gson version, we write golden tests: for each important type, serialize a representative object and store the exact output as an approved file, and deserialize the stored files back and compare the objects.

Java
@ParameterizedTest
@MethodSource("fixtures") // one fixture per type: Money, Instant, PaymentMethod, ...
void matchesGolden(String name, Object value) throws Exception {
String json = codec.toJson(value); // Gson today, Jackson later
JSONAssert.assertEquals(read("golden/" + name + ".json"), json, JSONCompareMode.STRICT);
assertEquals(value, codec.fromJson(read("golden/" + name + ".json"), value.getClass()));
}

Notice that the test calls a small codec interface, not Gson directly. Today it is backed by Gson; after the migration the same tests run against Jackson. The golden files, written from the current behaviour, are now the definition of correct. We include awkward cases on purpose: nulls, empty lists, very large and very precise numbers, unknown properties and unknown enum values.

2Map Each Adapter to a Jackson Feature

Most Gson adapters fall into a few patterns, and each pattern has a natural Jackson counterpart. A type written as a single value, such as Money as "12.50 EUR", becomes @JsonValue on a method that returns the string and @JsonCreator on a factory that parses it. A type whose structure is reshaped becomes a JsonSerializer and JsonDeserializer pair, usually extending StdSerializer and StdDeserializer, registered in a Jackson Module. When we cannot annotate the class, because it comes from another library, a mix-in, an annotated stand-in class that Jackson applies to the real class, carries the annotations. Polymorphic factories map to @JsonTypeInfo and @JsonSubTypes, with the same short type names.

Typical Gson pieces and their Jackson equivalents
GsonJackson
TypeAdapter writing one string@JsonValue plus @JsonCreator
TypeAdapter reshaping an objectStdSerializer and StdDeserializer in a Module
Adapter for a class we cannot changemix-in or a module serializer
Polymorphic TypeAdapterFactory@JsonTypeInfo and @JsonSubTypes
@SerializedName(alternate = ...)@JsonProperty plus @JsonAlias
InstanceCreator@JsonCreator constructor or factory
ExclusionStrategy@JsonIgnore, mix-ins or a filter

We write down the mapping for all 30 adapters in the migration plan. Adapters that do not fit a pattern get a closer look, because they usually encode an odd rule that a client depends on.

3Line Up the Defaults

Even with every adapter mapped, plain Jackson would still produce different JSON, because its defaults differ from Gson's. Gson reads and writes fields, while Jackson uses getters and setters, so a computed getter would suddenly appear in the output. Gson omits null fields, while Jackson writes them. Gson ignores unknown properties, while a plain ObjectMapper fails on them (Spring Boot's configured mapper does not). Numbers and dates have their own differences. So we configure the library's mapper to match the golden files.

Java
ObjectMapper mapper = JsonMapper.builder()
.visibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE)
.visibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY) // fields, like Gson
.serializationInclusion(JsonInclude.Include.NON_NULL) // omit nulls, like Gson
.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) // ignore unknown, like Gson
.addModule(new ClientLibraryModule()) // the 30 mapped adapters
.build();
// Jackson 2.x API shown; Jackson 3 renames some builder methods, so check your version

The library should own this mapper and not reuse whatever ObjectMapper the consuming application has, because the application may configure its mapper differently. This is the step where the golden tests start passing one by one.

4Run Both Side by Side on Real Payloads

Golden files only cover the cases we thought of. To catch the rest, we record a sample of real production payloads, requests and responses, with personal data removed, and run every one through both implementations: parse with Gson and with Jackson and compare the resulting objects, then serialize both and diff the JSON.

Step throughVerifying the migration
  1. Golden tests pass on Gsoncurrent behaviour recorded
  2. Map adapters and configure Jackson
  3. Golden tests pass on Jackson?
    YesRun recorded payloads through bothNoFix the mapping
  4. Any diff in parsed objects or JSON?
    YesTriage: bug, intended change or harmlessNoReady to release
  5. Release new major versionold major patched for a period

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

Each difference is triaged: a bug in our mapping, a deliberate improvement to be released as a visible change, or a harmless difference such as field order. We only move on when every difference has a decision. For a library this size, a few hundred thousand payloads run in minutes and find the cases nobody would have written by hand, like a legacy client sending numbers as strings.

5Release as a New Major Version

Even a perfect migration changes the library's dependencies: consumers now get Jackson instead of Gson, and any of their code that used the library's Gson types, such as a public method returning Gson or JsonElement, breaks at compile time. So the change goes out as a new major version, with a migration note that lists removed Gson types, any intended format changes, and how to configure things that used to be configured through Gson.

We keep the previous major version patched for security and critical bugs for an agreed period, for example six months, so teams can migrate during their normal work instead of on our deadline. We track adoption across services and announce the end of support well in advance.

6Follow-up questions

Why not migrate adapter by adapter inside the same version?

Because a library cannot sensibly use Gson for some types and Jackson for others in one object graph: a Gson-serialized object containing a Jackson-only type would not work. The internal migration can be done step by step on a branch, guarded by the golden tests, but it ships as one switch.

How do we handle a format we actually want to fix during the migration?

We separate it from the migration. First we release a Jackson version that reproduces the old format exactly, so consumers only change dependencies. A format fix then goes out as its own, explicitly announced change, ideally behind a versioned API, so if something breaks we know which change caused it.

What if consumers also use Gson directly?

That is their own choice and is not affected, as long as the library no longer exposes Gson types in its API. Removing those types from the public API is part of the major version, and it is what finally stops the library from forcing Gson on its users.

7Conclusion

In this answer, we planned the migration of a Gson library with 30 adapters around evidence. We recorded current behaviour as golden tests first, mapped every adapter to a Jackson serializer, deserializer, mix-in or @JsonCreator and @JsonValue, configured Jackson to use fields, omit nulls and ignore unknown properties like Gson, and verified by diffing both libraries over recorded production payloads. We shipped it as a new major version with a migration note, keeping the old version patched for a period.

What to say in the interviewAbout 80 seconds aloud

Open with

I would start by building a safety net before changing any code. I would inventory all 30 adapters, what type each handles and what JSON it produces, and write golden tests on the current Gson version that serialize representative objects and compare them with stored JSON, including nulls, empty lists, big numbers and unknown values.

Then, if they want more

The tests call a small codec interface so the same tests can later run against Jackson. Then I map each adapter: single-value types to @JsonValue and @JsonCreator, reshaped objects to serializers and deserializers in a Jackson module, classes I cannot change to mix-ins, and polymorphic factories to @JsonTypeInfo with the same type names.

Next I configure the library's own ObjectMapper to match Gson's defaults, because Gson uses fields and omits nulls and ignores unknown properties, while Jackson uses getters, includes nulls and a plain mapper fails on unknown properties.

When the golden tests pass, I run recorded, anonymized production payloads through both libraries and diff the parsed objects and the output, triaging every difference. Finally I release it as a new major version with a migration note, and keep patching the old major version for an agreed period so consuming teams can move on their own schedule.

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 shared client library uses Gson with 30 custom type adapters, and you are migrating it...": https://scrivio-interview-library.netlify.app/java/json-libraries/2ccc8fad58/