Scrivio Interview library
DesignAdvanced7 min read · updated 12 November 2026

You maintain a Jakarta EE application server based product and a Spring Boot product. Should shared libraries depend on JSON-B, Jackson, or neither? Explain the design.

Shared libraries should depend on neither JSON-B nor Jackson in their core. If a shared library hard-codes one JSON library, it forces that library and its version on every consumer and causes conflicts on both products. Instead, we keep the domain types library-neutral, plain records without JSON annotations, and ship two small adapter modules, one for Jackson and one for JSON-B, each verified by the same contract tests; the alternative of depending only on the Jakarta JSON-P and JSON-B APIs works when the Spring Boot product is willing to carry a JSON-B implementation too.

Why this question is asked

Shared libraries are where dependency decisions spread fastest: one choice in a common module becomes a choice for every application that uses it. With two products on different runtimes, a Jakarta EE application server and Spring Boot, the wrong choice shows up as version conflicts, two JSON stacks in one application or annotations that silently do nothing. Interviewers ask this to see whether we can design a library boundary rather than just pick a favourite library. In this answer, we will look at what goes wrong when a shared library picks a JSON library, then design the neutral core with adapters, compare it with depending only on the Jakarta APIs, show how contract tests keep the adapters in line, and weigh the maintenance cost.

1What Goes Wrong When the Shared Library Picks One

Suppose the shared library, call it pricing-model, adds Jackson annotations to its types and depends on jackson-databind. On the Spring Boot product this looks fine until the library's Jackson version differs from the one Spring Boot manages, and the build resolves to a version that one of them was not tested with. When the Spring Boot product moves to Boot 4 and Jackson 3, whose core lives in new packages, the library's Jackson 2 dependency is now a second JSON stack, and its annotations may not be applied by the mapper the application actually uses; check your versions, as Jackson 3 kept the annotation package for compatibility.

On the Jakarta EE product the problem is the reverse. The application server already provides JSON-B, so the Jackson dependency is pure weight, and the Jackson annotations on the shared types mean nothing to JSON-B. The team ends up writing a second set of mapping rules anyway, only now the types also carry annotations that look meaningful but are ignored.

Doing it the other way round, with JSON-B annotations in the shared types, simply moves the same problems to the Spring Boot product.

2Design: A Neutral Core and Two Adapters

The core module holds the domain types as plain Java: records, enums and value classes, with no JSON imports at all. It describes what the data is, not how it is written. Next to it we publish two thin modules. pricing-model-jackson contains a Jackson Module that registers serializers, deserializers or mix-ins for the core types. A mix-in is a Jackson feature that lets us attach annotations to a class from the outside, so the core stays clean. pricing-model-jsonb contains JSON-B adapters and serializers, registered through JsonbConfig.

Each product depends on the core plus the adapter for its own runtime, and nothing else.

Java
// pricing-model (core): no JSON imports
public record Price(BigDecimal amount, Currency currency) {}
// pricing-model-jackson
public final class PricingJacksonModule extends SimpleModule {
public PricingJacksonModule() {
setMixInAnnotation(Price.class, PriceMixin.class);
}
abstract static class PriceMixin {
@JsonFormat(shape = JsonFormat.Shape.STRING) abstract BigDecimal amount();
}
}
// Spring Boot: a Module bean is registered with the auto-configured mapper
@Bean Module pricingModule() { return new PricingJacksonModule(); }
// pricing-model-jsonb
public final class PriceAdapter implements JsonbAdapter<Price, JsonObject> {
public JsonObject adaptToJson(Price p) {
return Json.createObjectBuilder()
.add("amount", p.amount().toPlainString())
.add("currency", p.currency().getCurrencyCode()).build();
}
public Price adaptFromJson(JsonObject o) {
return new Price(new BigDecimal(o.getString("amount")),
Currency.getInstance(o.getString("currency")));
}
}
Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withAdapters(new PriceAdapter()));
// both produce {"amount":"12.50","currency":"EUR"}
Step throughModules and who uses them
  1. Spring Boot productdepends on core + pricing-model-jackson
  2. Jakarta EE productdepends on core + pricing-model-jsonb
  3. pricing-model-jackson / pricing-model-jsonbthin adapters, JSON library in provided scope
  4. pricing-model-contract-testsshared approved JSON, run by both adapters
  5. pricing-model corerecords and enums, no JSON imports

5 layers, from the top down. Step through them one at a time.

The core never knows which JSON library will write it.

Notice that the adapters declare their JSON dependency with provided or compileOnly scope where the runtime supplies it, so they never drag a second version into an application. In Spring Boot, a Jackson Module bean is picked up by the auto-configured mapper; for Jackson 3 the module API moved packages, so the Jackson adapter may need one variant per major version.

3The Alternative: Depend Only on the Jakarta APIs

A simpler design is to make the shared library depend only on the jakarta.json and jakarta.json.bind APIs, with provided scope, and use JSON-B annotations directly. On the Jakarta EE product the server supplies Yasson and everything just works. On the Spring Boot product, though, the application must add Yasson, and it then runs two JSON stacks: Jackson for its HTTP layer and JSON-B for the shared types. That is workable when the shared library serializes only its own payloads, such as an event body it writes to a queue, but it breaks down when the shared types appear inside Spring MVC responses, because Jackson will serialize them and ignore the JSON-B annotations.

So the API-only approach suits libraries that own their serialization end to end, while the adapter approach suits types that applications embed in their own responses. The question to ask is: who calls the serializer?

4Keeping the Adapters in Sync With Contract Tests

Two adapters mean two chances to drift. The guard is one set of approved JSON documents, published as a test artifact, that both adapter modules run against. Each test serializes a known object, compares the result with the approved file, and parses the file back to check the round trip, including the awkward cases: null fields, empty lists, large and negative amounts, and unknown properties.

Java
// in pricing-model-contract-tests, shared by both adapters
public abstract class PriceContract {
protected abstract String write(Price p);
protected abstract Price read(String json);
@Test void writesAmountAsString() {
assertEquals("{\"amount\":\"12.50\",\"currency\":\"EUR\"}",
canonical(write(new Price(new BigDecimal("12.50"), Currency.getInstance("EUR")))));
}
@Test void roundTrips() {
Price p = new Price(new BigDecimal("-0.01"), Currency.getInstance("JPY"));
assertEquals(p, read(write(p)));
}
}
class JacksonPriceTest extends PriceContract { ... } // same tests, Jackson adapter
class JsonbPriceTest extends PriceContract { ... } // same tests, JSON-B adapter

Because both adapters inherit the same tests, a change to the format is made once in the approved files and both builds fail until both adapters follow.

5Weighing the Maintenance Cost

This design is not free. Every new public type needs a mapping in two adapters and a contract test, and the team must understand both libraries. The way to keep the cost small is to keep the public surface small: share a handful of value types and events, not the entire domain model. If the shared library would expose fifty types, that is a sign that the products are sharing too much, or that the shared unit should be a schema, such as JSON Schema or an OpenAPI document, from which each product generates its own classes.

I would choose the neutral core with adapters when the types are small, stable and used inside both products' own responses. I would choose API-only JSON-B when the library owns its own payloads, and a shared schema with generated code when the surface is large.

6Follow-up questions

Why not let each product write its own mapping and skip the adapters?

Then the same type would be serialized by two hand-written mappings maintained by two teams, and they would drift. The adapters plus shared contract tests are exactly that mapping, written once per library and checked against one definition of the format.

Are Jackson mix-ins slower than annotations on the class?

No meaningful difference. Jackson reads mix-in annotations once when it builds the serializer for a type and caches the result, so after the first use the cost is the same as with annotations written on the class itself.

How do records help here?

Records give a canonical constructor and accessor methods that both Jackson and JSON-B implementations understand in current versions, so plain records often need no mapping at all. The adapters then only handle the special cases, such as money as a string or dates in a fixed format, which keeps them small.

7Conclusion

In this answer, we saw that a shared library which hard-codes Jackson or JSON-B forces that choice and its version on every consumer, causing conflicts and ignored annotations. We designed a library-neutral core of plain records with thin Jackson and JSON-B adapter modules, compared it with depending only on the Jakarta APIs, which works when the library owns its own payloads, and kept the adapters honest with one shared set of contract tests. Finally, we kept the cost under control by keeping the shared public types few and small.

What to say in the interviewAbout 100 seconds aloud

Open with

I would make the shared libraries depend on neither in their core. If a shared module pulls in jackson-databind with annotations, the Jakarta EE product gets a JSON stack it does not need and annotations JSON-B ignores, and the Spring Boot product gets version conflicts with what Boot manages, especially across the Jackson 2 to 3 move.

Then, if they want more

The reverse choice just moves the pain. So the core module contains plain records and enums with no JSON imports, and next to it I publish two thin adapter modules: one with a Jackson Module that uses mix-ins or custom serializers, registered as a bean in Spring Boot, and one with JSON-B adapters registered through JsonbConfig.

The JSON library is a provided dependency in each adapter, so the runtime's version wins. To keep the two adapters producing the same JSON, I would publish a contract test artifact with approved documents and an abstract test class that both adapters extend, covering nulls, empty lists, money and round trips.

An alternative is to depend only on the Jakarta JSON-P and JSON-B APIs and let the runtime supply Yasson; that is fine if the library serializes its own payloads, but not if the types end up in Spring MVC responses, where Jackson does the writing.

The cost of the adapter design is keeping two mappings in sync, so I would keep the shared types few and small, and if the surface grows, share a schema and generate code instead.

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 "You maintain a Jakarta EE application server based product and a Spring Boot product....": https://scrivio-interview-library.netlify.app/java/json-libraries/d3ae569296/